Try this 😉
var score = 0;
var questions = [
['Question One?', '1 Answer'],
['Question Two?', '2 Answer'],
['Question Three?', '3 Answer'],
['Question Four?', '4 Answer'],
['Question Five?', '5 Answer'],
['Question Six?', '6 Answer']
];
var cA = [];
var incorrect = [];
function askQuestion(question, index) {
var answer = prompt(question[0], '');
if (answer == question[1]) {
alert('Correct!');
score++;
cA = question;
} else {
incorrect.push(index);
alert('Sorry. The correct answer is ' + question[1]);
}
}
for (var i = 0; i < questions.length; i++) {
askQuestion(questions[i], i);
}
var message="You got " + score;
message += ' out of ' + questions.length;
message += ' questions correct.<br>' + cA;
message += '<br><br>You answered ' + incorrect.length;
message += ' questions incorrect. These are as follows:';
for(var i in incorrect){
message += '<p>Q ' + (incorrect[i] + 1) + '. ' + questions[incorrect[i]][0] + '<br>' + questions[incorrect[i]][1] + ' </p>';
}
document.write('<p>' + message + '</p>');
solved Showing Correct and Incorrect in a quiz [closed]