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

correctAnswer not working?

So everything is seems to be working fine except my correctAnswer counter in the print message at the bottom of my funciton

var questions = [
['How many states in the U.S.?', 50],
['What\'s the name of your cat?', 'Caesar'],
['What is your name?', 'Nate']

var corectAnswer = 0;
var question;
var answer;
var response;
var html;

function print(message) {

 function Quiz (list) {
while (true) {

for (var i = 0; i < list.length; i += 1 ) {
response = prompt(list[i][0]);
  answer = list[i][1];
  response = response.toLowerCase();

   if (response = 'quit') {
    else if (response === answer) {
    correctAnswer += 1;
   print('You got ' + corectAnswer + ' questions right');



2 Answers

Matt Johnson
Matt Johnson
Courses Plus Student 2,735 Points

Looks like you're just missing the 'r' in the function. You have 'corectAnswer' as the variable, but in the IF statement you have 'correctAnswer'

haha! wow. I was going mad for the smallest fix. Thank you.

So I fixed the 'correctAnswer' to be spelled correctly everywhere... but I'm noticing that my 'quit' is no longer working... and the 'correctAnswer' counter still isn't working.

Matt Johnson
Matt Johnson
Courses Plus Student 2,735 Points

To have 'quit' work, you should have 2 or 3 '=' in order to compare the result 'response' to 'quit'. One '=' is an assignment.

Also, put your logical statement (if, else if) within the for loop. Since it is not within the loop now, it's not counting your responses. To get the counter to work, I removed one of the '=' from the comparison on the else if. The issue you'll run into now is that if you lowercase the response but not the answer, they won't compare to be equal.