New to coding attempting to learn JavaScript Functions all of them work in the following code except gameOver() unsure why it is not functioning
var quiz = [
["What is Superman's real name?", "Clarke kent"],
["What is Wonderwoman's real name?", "Dianna Prince"],
["What is Batman's real name?", "Bruce Wayne"]
];
var score = 0 // initalize score
play(quiz);
function play(quiz) {
// main game loop
for(var i=0, question, answer, max=quiz.length; i<max; i++) {
question = quiz[i][0];
answer = ask(question);
check(answer);
}
//end of main game loop
gameOver();
function ask(question) {
return prompt(question); // quiz[i][0] is the ith questions
}
function check(answer) {
if (answer === quiz [i][1]) { //quiz [i][1] is the ith answer
alert("Correrct!");
// increase score by 1
score++;
} else {
alert("WRONG!");
}
function gameOver() {
// inform player game is over and their score
alert("Game Over, you scored " + score + " points");
}
}
}