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 trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Build a Quiz Challenge, Part 1 Solution

No 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) {

var questions = [
  ['how?',15],
  ['why?',9],
  ['see?',7]  //remove comma from here
]
for (m = 0; m                              //what is this i think loop is not declared properly
  question = question[m][0];  
  answer = question[m][1];
  response = parseInt(prompt(question));

  }

Check 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.

As 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.

A weird bug, huh? Thanks for the correction.

Yeah - 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

You 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 = question
s*[m][1];

Oh, really! I have been blind all along.