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

martin wong
martin wong
4,799 Points

document.write wont print

var counter = 0;
var conclusion;
var userGuess;
var answer;

var QuestionAndAnswer = [ 
["What is the capital of Great Britain?" , "London"],
["Which member left the boyband One Direction to pursue a solo career?" , "Zayn Malik"],
["What team won the Premier League in the 2016-17 season?" , "Chelsea"]

for (i = 0; i < QuestionAndAnswer.length; i+=1) { 
  QuestionAndAnswers  = QuestionAndAnswer [i] [0];
  answer = QuestionAndAnswer [i] [1];
  userGuess = prompt(QuestionAndAnswers);
  userguess = userGuess.toLowerCase();

  if (userGuess === answer) {
  correct +=1;

var html;
function print(message) {

html = "You got" + correct + "right!.";


The code will not print how many answers i get right!. where am i going wrong? I have looked over the video code and mine for the print() and as far as i can see, i am doing the same thing

I am super demotivated by this course and feel like i cant go anywhere. Any other resources or something to help me out?

1 Answer

Steven Parker
Steven Parker
229,644 Points

This code increments a variable named "correct" when the given answer matches, and also uses "correct" to print the final result, but no variable by that name was ever established.

I'd guess you meant to put "var correct = 0;" up near the beginning of the program.

martin wong
martin wong
4,799 Points

Thank you very much!