Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

Heidi Vasterling-Ford
Heidi Vasterling-Ford
7,805 Points

Trying to use .toLowerCase instead of parseInt, because my answers aren't numbers and it's not working. Anyone, help?

var correctAnswers = 0; var question; var answer; var response; var html; var questions = [[ 'What period of art is Picasso most commonly associated with?', 'cubism' ], ['What is the setting of Monets most famous painting?', 'garden'], ['What is the oldest sculpture of a woman we have today?', 'venus of willendorf'] ];

function print(message) { document.write(message); }

for ( var i = 0; i < questions.length; i += 1) { question = questions[i][0]; answer = questions[i][1]; response = answer.toLowercase(prompt(question)); if (response === answer) { correctAnswers += 1; } }

html = "You got " + correctAnswers + " correct!"; print(html);

//I believe my issue lies in the "response = " line of code, but I just can't crack it

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,822 Points

Your are correct, your line below doesn't make sense. First the 'c' in case needs to be upper case toLowerCase() and second, you are setting the response = to the answer and then checking to see if they are equal, your if statement will always return true.

response = answer.toLowercase(prompt(question));

// Try changing to this:
response = prompt(question).toLowerCase(); 
// or even better, to ensure answer is lower also - do the lower stuff in the if
response = prompt(question);

  if (response.toLowerCase() === answer.toLowerCase())