I have five questions to a user that require user answers. Correct answers are counted and then the user is graded at the end.
I would like the grading of each questions to appear immediately after each respective question, not after all have been asked. As it is now, it asks 2 out of 5 questions and then provides a response to the user but only after the questions are all asked. The order is: (ask, ask, answer, answer) but I need it to be (ask, answer, ask, answer) but I can't figure out why it's not doing that.
// Counters
var numberOfQuestions = 5;
var correctAnswers = 0;
// The five questions
var raining = prompt("Is it raining today?");
var married = prompt("Am I married?");
/* Remaining questions
var day = prompt("What day is it?");
var threes = prompt("What does 3 + 3 + 3 equal?");
var number = prompt("What number am I thinking of?");
*/
// First question - Is it raining
if (raining.toUpperCase() === "NO") {
correctAnswers += 1;
alert("Correct. \nYou have " + correctAnswers + " correct answers out of " + numberOfQuestions);
} else {
alert("Don't you wish it was. \nYou have " + correctAnswers + " correct answers out of " + numberOfQuestions);
}
// Second question - Am I married
if (married.toUpperCase() === "YES") {
correctAnswers += 1;
alert("Correct! I am married. \nYou now have " + correctAnswers + " correct answers out of " + numberOfQuestions);
} else {
alert("Incorrect, I am married. \n You still have " + correctAnswers + " correct answers out of " + numberOfQuestions);
}
Any help would be most appreciated.