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

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,814 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,814 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! :)