mercredi 23 septembre 2015

JavaScript Quiz Validating with onClick Function?

I am trying to create a JavaScript Quiz. The function will check the user's input value. If it is correct; it will change the question.

Exact Code See JSFiddle

There are probably many more efficient and conventional ways to achieve what I am trying to do. Current issue is the function runs from the top every time it runs(obviously)

function checkAnswer() {

  var question = document.getElementById("ques").innerHTML;

  var userAnswer = document.getElementById("answer").value;

  if (userAnswer === "New York City") {

    alert("correct!");
    question = "What is the best college football team?";

    if (userAnswer === "Alabama") {
      alert("Correct!");
      question = "Next question will go here and so on..."

    }
  }
}

Aucun commentaire:

Enregistrer un commentaire