I am trying to make a question where you type in the answer and submit to see if you are correct or false. But for some reason even when I put in the right answer in the input to the question, it still says false.
Javascript code:
var qAnswer = document.getElementsByClassName(“P7”)[0];
var question1 = document.getElementById(“question1”).value;
function check(){
if (question1 == “2007”){
qAnswer.innerHTML = "Correct";
} else {
qAnswer.innerHTML = “False”;
}
qAnswer.style.visibility = “visible”;
}
HTML code:
Document <h1>Second Question...</h1>
<p>When did Cod 4 get released?</p>
<p class="P6">Type in your answer</p>
<input id="question1" type="text">
<button type="button" class="S1" onclick="check()">Submit</button>
<p class="P7"></p>