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

The questions section doesn't add the score.

Here is my code. I can't understand why the tally doesn't work for this section. When I finish the quiz no matter what I do, the correctAnswers section doesn't show the right score even if I answer the questions with the correct string.

var questions = [ ['How many states are in the United States?', 50], ['How many sides in a triangle?', 3], ['How many in a pair?', 2] ];

var correctAnswers = 0;

var question; var answer; var response; var html;

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

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

html = "You got " + correctAnswers + " question(s) right."; print(html);

1 Answer

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

Hi there, ainorororo ! It looks like you're doing fantastic from what I can tell. In fact, you are super close here and it boils down to a single character typo.

You typed:

reponse = parseInt(prompt(question));

But that variable is missing an "s". You meant to type:

response = parseInt(prompt(question));

Note the missing "s" between the "e" and "p" of the first one. Because of this, there's a new variable being made named reponse and it contains the answer the user typed in. Then immediately later, you compare the variable response (which is still undefined at this point) to answer. Because undefined will never equal the string the user is putting in, this will always fail and the correct count won't go up.

The solution is to change that reponse to response.

Hope this helps! :sparkles: