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 trialainorororo
5,821 PointsThe 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
Treehouse TeacherHi 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!