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

My array challenge solution:

let answers = []; let questionsCorrect = []; let questionsWrong = []; let answersCorrect = 0;

const quiz = [ ['What year did Joe Rogan move to Austin?', '2020'], ['When was the Spanish Flue Pandemic?', '1918'], ['Who won the 2020 presidential election?', 'joe biden'] ];

for ( let i = 0; i < quiz.length; i++ ) { let question = quiz[i][0];

answers.push(prompt(question).toLowerCase());
 if ( answers[i] === quiz[i][1] ) {
    answersCorrect++;
    questionsCorrect.push(question);
} else {
    questionsWrong.push(question);
}

};

function arrLoop(arr) { let message = '';

for ( let i = 0; i < arr.length; i++) {
    message += `<li>${arr[i]}</li>`;
};
return message;

}

let html = <h1>You got ${answersCorrect} question(s) correct</h1> <h2>You got these questions right:</h2> <ol> ${arrLoop(questionsCorrect)} </ol> <h2>You got these questions wrong:</h2> <ol> ${arrLoop(questionsWrong)} </ol>

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