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

Build a Quiz 1 Solution

const qATest = [
  ['What color is the moon?', 'white'],
  ['What year was Javascript born?', '1995'],
  ['What is the name of the crypto sock business?', 'sockhodler'],
  ['Will I ever become a true programmer?', 'yes']
];

let answerCorrect = 0;

for ( let i = 0; i < qATest.length; i++ ){
  const questions = prompt(qATest[i][0]);
  if (questions.toLowerCase() === qATest[i][1]) {
    answerCorrect++;
  }
}

document.querySelector('main').innerHTML = `

<h1>You got ${answerCorrect} question(s) correct</h1>

`;

Please let me know if anyone has any feedback on how to improve my code at this point.

1 Answer

Steven Parker
Steven Parker
229,608 Points

Looks good so far. As shown later in the video, the instructor uses arrays and a function to make the code a bit more compact, but that's only a slight improvement and not necessary at all to meet the stated objectives.

Good job!   :+1: