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 2 Solution

Can someone review my code please I can't get the results to appear?

function print(message) { var pageLocation = document.getElementById("output"); pageLocation.innerHTML = message; }

var quizQuestions = [ ['What date is Christmas Day?', 25], ['How many days are there in a year?', 365 ], ['What is the maximum score on a snooker table?', 147], ]

var counter = 0; var userResponse; var actualAnswer; var correctList = []; var wrongList = [];

for (var i = 0; i <= quizQuestions.length; i += 1) { var question = prompt(quizQuestions [i][0]); answer = (quizQuestions [i][1]);

    if (question === parseInt(answer)) {
      counter += 1;
    } else {

function orderList (arr){ var list = "<ol>"; for (i=1; i <= arr.length; i + 1) {

    list += ("<li>") + (arr[i]) + ("</li>");
    list += ("</ol>");
    return list;


print("You got total of " + counter + " questions correct!"); print("You got these questions correct" + orderList(correctList)); print("You got these questions wrong" + orderList (wrongList));

1 Answer

Dave StSomeWhere
Dave StSomeWhere
19,870 Points

Sure, after a quick look here's some to do items for you:

  1. Check the markdown cheatsheet below :arrow_heading_down: to properly post your code.
  2. Both your for loops are incorrect, double check the conditions, remember the index starts at zero and the length starts at one. If you have 3 items (like questions). The length will be 3 and the indexes will be 0, 1 and 2.
  3. You are doing the parseInt() on the wrong value in yourif` condition.
  4. You are pushing the wrong values for your correctList and wrongList
  5. console.log() is your friend, try checking values all over your code

That's what pops out immediately. Just ask if you need anything additional. :tropical_drink: :palm_tree: