Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Owen Boochever
Owen Boochever
14,582 Points

Hi guys! Having difficulty getting my browser to "prompt". Is my code off, or is there something else going on?

I know this isn't the right code for the video, just illustrating what I'm working with. The loop is not working, nor are either of the prompts outside of it. Thank you!!

var questions = [
   ['q1', 'answer1'],
   ['q2', 'answer2'],
   ['q3', 'answer3']

var correctAnswers = 0;
var question;
var answer;
var response;
var html;

function print(message) {

for (i = 0; i < questions.length; i+= 1) {
  question = questions([i][0]);
  answer = questions([i][1]);
  response = prompt(question);


3 Answers

You're probably seeing errors because your i variable is undefined. You should have it as:

for (var i = 0; i < questions.length; i+= 1)
Owen Boochever
Owen Boochever
14,582 Points

Got it! Had another issue with my code that didn't copy. Thank you.

It's because you have parenthesis wrapped around your array elements in the loop, you are treating it as if questions was a function and the array elements are its parameters which is not the case, this is causing an error which is preventing your code from executing properly. It should be:

    question = questions[i][0];
    answer = questions[i][1];