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 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

Joseph Yhu
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Joseph Yhu
PHP Development Techdegree Graduate 47,388 Points
  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!