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 trialdanielleryan
3,381 PointsCan 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;
correctList.push(question);
} else {
wrongList.push(question);
}
}
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
19,870 PointsSure, after a quick look here's some to do items for you:
- Check the markdown cheatsheet below to properly post your code.
- 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.
- You are doing the
parseInt() on the wrong value in your
if` condition. - You are pushing the wrong values for your correctList and wrongList
-
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.