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 trialStanley Wilkins
685 PointsNo prompt for questions
Here is the code from the video, but no questions show up when I run it:
var questions = [
['how?',15],
['why?',9],
['see?',7],
]
var correctAnswers = 0;
var question;
var answer;
var response;
var html;
function print(message) {
document.write(message);
}
for (m = 0; m *less than* questions.length; m += 1) {
question = question[m][0];
answer = question[m][1];
response = parseInt(prompt(question));
}
but prompting works when I write something simple like this:
var pass = prompt("What is the password")
if (pass == "hack") {
confirm("welcome");
} else {
window.close();
}
p.s: For loop doesn't show up correctly when I paste code here, I set m less than the length of questions and incremented it by 1. ... m < questions.length; m += 1) {
Stanley Wilkins
685 PointsCheck my note : For loop doesn't show up correctly when I paste code here, I set m less than the length of questions and incremented it by 1. ... m < questions.length; m += 1) { Removed the comma but still doesn't work.
Steve Hunter
57,712 PointsAs soon as you use a less than or greater than symbol, the formatting goes to pot! I can see when I edit your post that the loop is set up correctly, i'll edit it to be a little clearer.
Stanley Wilkins
685 PointsA weird bug, huh? Thanks for the correction.
Steve Hunter
57,712 PointsYeah - I think it stems from the HTML origins of the formatter. It drives me nuts at times!! You might be able to escape the character out; I'll give it a try now.
[EDIT: Nope; I can't get it to work]
1 Answer
Lindsay Sauer
12,029 PointsYou had it, it was just a little typo: within the for loop, you are trying to assign question to itself (an undefined value) rather than the questions array. The correct code would be:
question = question*s[m][0];
answer = questions*[m][1];
Stanley Wilkins
685 PointsOh, really! I have been blind all along.
Ashish Mehra
Courses Plus Student 31 PointsAshish Mehra
Courses Plus Student 31 Points