Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,806 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,870 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())