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

Laura Camnasio
Laura Camnasio
4,720 Points

Can anyone help checking my work?

I have been checking my code and it seems correct to me, but it is not working. The prompt dialog box is not showing up...where have I been wrong?

var correctAnswer = 0;
var bandsQuestion = [
  ['Which band plays Revolution?', 'the beatles'],
  ['Which band plays Dark side of the moon?', 'pink floyd'],
  ['Which band plays Dymo?', 'verdena'],
  ['Which band plays Catartica?', 'marlene kuntz']
];


function print(message) {
  document.write(message);
}

for ( var i = 0; i < bandsQuestion.lenght; i += 1) {
 var guess = prompt(bandsQuestion[i][0]);
    if (guess.toLowerCase() === bandsQuestion[i][1]) {
      correctAnswer += 1;
    } else {
      alert('Bummer! Try again with next question.');
    }
}

print('You got ' + correctAnswer + ' correct guess(es).');
rydavim
rydavim
18,780 Points

I've added some code formatting to your post, to ensure that everything shows up correctly and to add fancy syntax highlighting. You can do this using the following markdown:

```language

your code here

```

1 Answer

rydavim
rydavim
18,780 Points

Looks like you just have a little typo.

for ( var i = 0; i < bandsQuestion.lenght; i += 1) // should be length

I believe that's the only issue, runs fine for me after fixing that. Nice job! Happy coding! :)