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 Arrays Multidimensional Arrays Build a Quiz Challenge – One Solution

Why the questions are not popping up?

This is my code and the questions are not even popping up. Why?

const questions = [["What is the capital city of France?", "Paris"], ["What is the capital of Spain?", "Madrid"], ["What is the capital of Slovakia?", "Bratislava"]
];

let correctAnswers = 0;

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

if (response === answer) { correctAnswers += 1; } }

let html = <h1>You guessed ${correctAnswers} question(s).</h1>;

document.querySelector("main").innerHTML = html;

1 Answer

  1. You have a typo: for (let i = 0; i < questions.lenght; i++)
  2. This should just be question, not questions: prompt(questions);
  3. This, <h1>You guessed ${correctAnswers} question(s).</h1>, should be surrounded by backticks.

Got it. Thank you!