JavaScript JavaScript Arrays Multidimensional Arrays Improve the Quiz – One Solution

Amy Tomey
Amy Tomey
8,599 Points

getting a console error: quiz.js:51 Uncaught SyntaxError: Unexpected end of input.

At one time, it DID prompt asking the questions, but it stopped when I added the loop and document query.

here is my code: // 1. Create a multidimensional array to hold quiz questions and answers

const questions = [ ['How many donuts are in a bakers dozen?', '13'], ['How many quarts in a gallon?', '4'], ['How many minutes in a quarter of an hour?', '15'] ]; // 2. Store the number of questions answered correctly

const correct = []; const incorrect = []; 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++; correct.push(question); } else { jncorrect.push(question);
} }

function createListItems(arr) { let items = ''; for (let i = 0; i < arr.length; i++) { items += <li>${arr[i]}</li>; } return items;

// 4. Display the number of correct answers to the user let html =` <h1>You got ${correctAnswers} question(s) correct</h1> <h2>You got these questions right:</h2> <ol><${createListItems(correct)}/ol>

<h2>You got these questions wrong:</h2> <ol>${createListItems(incorrect)}/ol> `;

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

1 Answer

Robert Manolis
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Robert Manolis
Treehouse Guest Teacher

Hi Amy Tomey, Looks like the problem might be with this part of your code:

if (response === answer){ correctAnswers++; correct.push(question); } else { jncorrect.push(question);
} }

Looks like you're trying to push to the jncorrect array instead of incorrect array.