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 trialNicholas Mullesch
2,489 PointsHere is my solution
// 1. Create a multidimensional array to hold quiz questions and answers
const quiz = [
['What is Mooning?', 'Bitcoin'],
['Why is mooning?', 'Tis Best Coin'],
['Do you have enough?', 'No']
];
// 2. Store the number of questions answered correctly
let correct = 0;
let incorrect = 0;
/*
3. 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
*/
const correctAnswers = [];
const incorrectAnswers = [];
for (i = 0; i < quiz.length; i++) {
let response = prompt(quiz[i][0]);
if ( response === quiz[i][1] ) {
correct++
correctAnswers.push(quiz[i][0]);
}
else {
incorrect++
incorrectAnswers.push(quiz[i][0])
}
};
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
document.querySelector('main').innerHTML = `
<h1>You got ${correct} answsers correct!</h1>
<h2>You got these questions correct:</h2>
<ol>${ createListItems(correctAnswers) }</ol>
<h2>You got these answers incorrect!</h2>
<ol>${createListItems(incorrectAnswers)}</ol> `
1 Answer
Steven Parker
231,275 PointsGood job on the coding.
But I don't understand the actual questions and answers!
Nils Kriedner
Full Stack JavaScript Techdegree Graduate 30,933 PointsNils Kriedner
Full Stack JavaScript Techdegree Graduate 30,933 Points😅