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

Ivana Lescesen
Ivana Lescesen
19,442 Points

Can someone help me ?

What is wrong with my code? Thank you so much :)

var correctAnswer = 0;

var questions = [
  ['what is the capital of sweden', 'stokholm'],
  ['What is my favorite TV show', 'COMMUNITY'],
  ['What is my favorite movie', 'Love Actually'],

var answer;

function print(message) {

function askQuestions( quiz ) {
  for ( var i = 0; i < quiz.length; i += 1) {

     answer = prompt(quiz[i][0]);
     answer = answer.toLowerCase();

        if (answer == quiz[i][1]){
          print( 'That is correct ');
         } else {
            print( 'sorry '); 



document.write("<p>You got " + correctAnswer + " out of 3 questions correct.</p>")

Moderator Edited: Added Markdown to the code block so it is readable in the forum. Please refer to the Markdown cheatsheet for formatting instructions. <code> elements don't work with Markdown.

Steven Parker
Steven Parker
229,657 Points

:x: message is a function argument. Those don't need to be defined.

1 Answer

Steven Parker
Steven Parker
229,657 Points

:point_right: You didn't describe your problem, but I do notice one functional issue:

It looks like you're converting the user's answer to lower case, but then comparing it to stored answers which contain upper case characters. Only answers stored as lower case can match a correct answer.

Happy coding!   -sp:sparkles: