JavaScript Functions

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


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);
  //end of main game loop
  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
      // increase score by 1
    } else {
    function gameOver() {
      // inform player game is over and their score
      alert("Game Over, you scored " + score + " points");

I figured it out with some debugging! I was placing the function in the incorrect spot

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.