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

Micah Angelica Baguio
Micah Angelica Baguio
3,108 Points

Build a Quiz Challenge

It won't display the "correct answers or responses" after. It's just completely blank

const questions = [ ['What is the nearest planet towards the Sun?', 'Mercury'], ['What is the second nearest planet towards the sun?', 'Venus'], ['What is the third nearest planet towards the sun?', 'Earth'], ['Name of the planet next to planet Earth', 'Mars']


// 1. Create a multidimensional array to hold quiz questions and answers

// 2. Store the number of questions answered correctly

let correctAnswers = 0; /*

  1. Use a loop to cycle through each question

    • Present each question to the user
    • Compare the user's response to answer in the array
    • If the response matches the answer, the number of correctly answered questions increments by 1 */ for ( let i = 0; i < questions.length; i++ ) { let question = questions[i] [0]; let answer = questions[i] [1]; let response = prompt(question);

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

// 4. Display the number of correct answers to the user

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

document.querySelector('main').innerHTMl = html;

1 Answer

Steven Parker
Steven Parker
217,626 Points

There's just a little typo on the last line where the code has "innerHTMl" (with a lower case "l") instead of "innerHTML".

For future reference, you might want to take a look at this video about Posting a Question, and also this one about sharing a snapshot of your workspace. And for when code must be added to a post instead of using a snapshot, see this video about using Markdown formatting to preserve the code's appearance.

Steven Parker
Steven Parker
217,626 Points

Micah Angelica Baguio — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!