I'm a programming newbie and am working through a quiz from Treehouse. I don't want to just look at the solution but I'm stuck. I want to store each correct question in a new array and the same for each wrong question, then print them out. My code keeps track of each right and wrong question, but it's only saving one question to each new array, even if more than one is correct or incorrect. I'm sure it's something simple, but what am I doing wrong?
var questions = [
['How many states are in the United States?', '50'],
['How many legs does a spider have?', '8'],
['How many continents are there?', '7']
];
function quiz(quizQuestions) {
var counter = 0;
for (var i = 0; i < questions.length; i++) {
var answer = prompt(questions[i][0]);
if (answer === questions[i][1]) {
var correctAnswers = [questions[i][0]];
counter += 1;
} else {
var wrongAnswers = [questions[i][0]];
}
}
print('<h2>You got these questions right</h2>');
print(correctAnswers);
print('<h2>You got these questions wrong</h2>');
print(wrongAnswers);
var printQuestionsRight = '<h3>You got ' + counter + ' questions right</h3>';
print(printQuestionsRight);
}
function print(message) {
document.write(message);
}
quiz(questions);
arraythanvariable