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 trialEnemuo Felix
1,895 PointsQuiz challenge part 1
Please i just did the challenge, but the code won't run. Someone should kindly point me to the right direction. I already added comments to the areas i'm not sure of. I will also appreciate if other wrong areas are pointed out.Steven Parker
function print(message) {
document.write(message);
}
var count = 0;
var questions = [
['What letter is the first alphabet?', 'a'],
['Who won the last world cup?', 'germany'],
['What is the capital of germany?', 'berlin']
];
var correctAnswer = [];
var wrongAnswer = [];
for (var i = 0; i > questions.length; i +=1) {
var userInput = prompt(questions[i][0]);
if(questions[i][1].indexOf(userInput.toLowerCase() ) > -1) {
correctAnswer.push(questions[i][1]);// trying to push the correct input into the correctAnswer array//
count+=1;
} else {
wrongAnswer.push(questions[i][1]);// trying to apply the same with line 16 but this time in the wrongAnswer array//
}
}
print('<ol>' + correctAnswer + '</ol>');// to print out the correctAnswer to the page with each of them numbered//
print('<ol>' + wrongAnswer + '</ol>');//same with line 22//
2 Answers
Steven Parker
231,275 PointsHi, I was alerted by your tag.
Take a look at the conditional in your loop:
for (var i = 0; i > questions.length; i +=1) {
Since I begins at 0, it will not pass the condition of being larger than the length of the questions array. So the loop won't run. This may just be a typo, and perhaps you meant to use "<" instead of ">".
Enemuo Felix
1,895 PointsThank you so much. Will try and find a way to include that
Enemuo Felix
1,895 PointsEnemuo Felix
1,895 PointsOh my..... I can't believe I missed that. I need to learn a way of sporting such little errors. Thank you very much steve. Pls, there's something else, the arrays doesn't seem to be numbered . Am i using the
<ol></ol>
tag wrongly?Steven Parker
231,275 PointsSteven Parker
231,275 PointsThe ordered list should contain list items ("li"). You'll probably want a loop for each array to generate each individual array item wrapped in a set of
li
tags.Happy coding!