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 trialLee Cockcroft
5,147 PointsMy answers will not print
Hi this is probably something silly, but i can't find anything wrong with my code! I have used the print function, that didnt work! The loop goes through my code, but wont type the results! nothing will work,even an alert at the end. can some one please help
var questions=[
["what is my favorite color","yellow"], ["what is my favorite food","pizza"], ["what is mh favorite football team","Leicester"]
];
var count=0; var guess;
for(var i=0; 0<questions.length; i++){
guess=prompt(questions[i][0]);
if(guess===questions[i][1]){
count++;
}
}
document.write('You have guessed ' + count + ' questions correctly out of 3 total.');
2 Answers
Alexander Davison
65,469 PointsAha. Sneaky. This is your line of code:
for (var i = 0; 0 < questions.length; i++) {
which actually never will stop! This is because 0 is always be less than the length of questions. Let's prove it. The length of the questions is 3. When we compare and see if 0 < 3, it will always always be true. you probably meant to say:
for (var i = 0; i < questions.length; i++) {
Good luck! ~Alex
Lee Cockcroft
5,147 Pointsoh my god haha thank you so much!!! I knew it was something as small as that!!!
Thanks again!! :)
Alexander Davison
65,469 PointsCan you give me a "Best Answer" so that this question won't be in the "Unanswered Questions" section of the Community? Thank you very much! ~Alex