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 trialTristan Johnson
Courses Plus Student 3,022 PointsAsking me the questions twice?
Why is it asking me each question twice?
var questions = [ ['Ten plus two?', 12], ['Seven plus nine?', 16], ['Four plus six?', 10], ]; var correctAnswers = 0; var question; var answer; var response; var html;
function print(message) { document.write(message); }
for (var i = 0; i < questions.length; i +=1) { question = questions[i][0]; answer = questions[i][1]; response = prompt(question); response = parseInt(prompt(question)); }
1 Answer
David Abel
5,199 PointsBecause you are prompting the user twice: response = prompt(question); response = parseInt(prompt(question));
These are both prompting the user for a response. You only need: response = parseInt(prompt(question));
I also had the clean up the code a bit for it to work for me. I think you're missing a curly brace on your for loop.
Mark Miller
45,831 PointsMark Miller
45,831 PointsYou 'for' loop looks messy. I don't see the parenthesis ending after incrementing 'i' nor do I see an opening curly brace anywhere. You should have three things inside the parenthesis, separated by two semicolons. Then open the curly brace to set the execution. The var I = 0; is correct, but next should be the condition being tested. 'i' should never become larger than the length of the array that holds the questions and answers. Test for that in the parenthesis. You should increment 'i' for the third part of the parenthesis.