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 trialUche Onuekwusi
18,070 PointsThe second question keeps looping pls help me out
var questions = [ ["Who is the president of Nigeria ?", "buhari"], ["Dublin is the capital of which country ?", "ireland"], ["Manchester united football club is from which country ?", "england"]
]; var correctanswer= 0; var question; var response; var answer; var html;
for (var i = 0; i < questions.length; i=+1) { question = questions[i][0]; answer = questions[i][1]; response= prompt(question); response = response.toLowerCase(); if (response === answer ) { correctanswer=+1;
}
}
html = "you got " + correctanswer + " question(s) right" ;
document.write(html);
Steven Parker
231,275 PointsThe formatting ammarkhan is suggesting can be done by using the instructions in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Â Or watch this video on code formatting.
1 Answer
Steven Parker
231,275 PointsThe increment clause in your "for" loop is "i = +1
". This keeps setting the index to 1 (+1), which refers to the second question.
You probably intended to use the addition assignment operator to increment the value instead: "i += 1
".
ammarkhan
Front End Web Development Techdegree Student 21,661 Pointsammarkhan
Front End Web Development Techdegree Student 21,661 PointsI ran your code and it works fine. Can you explain more of what happens? You can also format the code to make it more presentable?