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

Ronny Rosabal
Ronny Rosabal
4,812 Points

No prompt on the quiz!

Using Safari browser for the course but I can't seem to get it to work. Right now I don't even get a prompt when I preview the code and I can't understand why. Any help will be greatly appreciated.

var questions = [
  ['What is the Lone Star state?', 'texas'],
  ['What is the Sunshine state?', 'florida'],
  ['Where is the Big Apple?', 'new york']
];
var correctAnswers = 0;
var rightAnswer = [];
var wrongAnswer = [];
var message = '';
var answer;

for( var i = 0; i < questions.length; i++ ){
  answer = prompt(questions[i][0]);
  answer.toLowerCase();
  if( answer === questions[i][1]){
    rightAnswer.push(questions[i][0]);
  }else{
    wrongAnswer.push(questions[i][0]);
  }
}
function print(message) {
  document.write(message);
}

for(var i = 0; i < rightAnswer.length; i++){
  message = '<h3>Right Answers</h3>';
  message += '<ol>';
  message += '<li>' + rightAnswer[i] + '</li>':
  message += '</ol>';
}

print(message);

Thank you

1 Answer

Justin Iezzi
Justin Iezzi
18,199 Points

Hey Ronny,

Check out this for loop -

for(var i = 0; i < rightAnswer.length; i++){
  message = '<h3>Right Answers</h3>';
  message += '<ol>';
  message += '<li>' + rightAnswer[i] + '</li>':
  message += '</ol>';
}

You'll see that you have a colon(:) where there should be a semicolon(;) instead.

Fix that, and it should work!

Ronny Rosabal
Ronny Rosabal
4,812 Points

Thanks for pointing that out. I changed the colon for a semicolon but I'm still not getting a prompt. I also tried the code in the Chrome console and it seems to work, so it may be a workspace issue.

Justin Iezzi
Justin Iezzi
18,199 Points

Hmm, worked for me when I tried it. Try doing a ctrl+F5, I think recently workspaces are having a hard time reloading everything. I may be wrong, but it's worth a try.

Ronny Rosabal
Ronny Rosabal
4,812 Points

Are you using a Windows machine or is that the ctrl on a Mac? I just tried the workspace in the Chrome browser and it worked.

Justin Iezzi
Justin Iezzi
18,199 Points

Nice, looks like it was a cache thing. ctrl+f5 just clears the cache for that page, I imagine it works on both Windows and OSX.