I need to do this without using parseInt but I'm not sure how to do it. I'm trying to check the answer against the actual value of a * b. I think what's wrong is that I'm not actually able to retrieve the textbox value. What is the best way to do that?
var answer = document.getElementById('answer');
var a = Math.floor((Math.random() * 12) + 1);
var b = Math.floor((Math.random() * 12) + 1);
document.getElementById('question').innerHTML = "What is " + a + " times " + b + "?";
function wrongRight() {
if (a * b == answer) {
document.getElementById('response').innerHTML = "Very good.";
} else {
document.getElementById('response').innerHTML = "No, please try again.";
}
}
<p id="response"></p>
<p id="question"></p>
<!-- this is where the x * x = ? will be asked-->
<p> your answer </p>
<input type="text" id="answer">
<input type="button" value="Click" onClick="wrongRight()">
Aucun commentaire:
Enregistrer un commentaire