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

Victor Gordian
Victor Gordian
4,656 Points

Doesn't show how many are right

var questions = [
['What color is the sky?', 'blue'],
['Whats the beginning of the Alphabet', 'a'],
['When its hot people usually like to eat what?', 'ice cream']  
];

var countA = 0;
var response;
var correct = [];
var wrong =[];


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

for ( var i = 0; i < questions.length; i += 1) {
  response = prompt(questions[i][0]);
  answer = questions[i][1];
    if ( response.toLowerCase() === answer.toLowerCase() ){
      countA += 1;
      correct.push(questions[i][0]);
     } else {
      wrong.push(questions[i][0]);
     }
}


html = 'You got ' + countA + 'question(s) right.';

2 Answers

Kirby Abogaa
Kirby Abogaa
3,058 Points

You need to make use of the print() function in your code. I which case, you need to add

print( html );

at the end.

And declare the variable html before assigning a value to it. Or just print the concatenated string instead of assigning it to a variable first.

Tim Signore
Tim Signore
835 Points

Hello, You need to target an element on your html page, and update it's innerHTML property. eg something along the lines of:

var mydiv = document.getElementById('myDiv');
mydiv.innerHTML =  'You got ' + countA + 'question(s) right.';
Victor Gordian
Victor Gordian
4,656 Points

hmm thanks but it still didnt work. I guess Im not good at capturing things.