I am basically trying to create a website that incorporates a math question generator (for grade 2 or 3 students) and when I run the code it gives me everything: the question, the check button, the output area, but whenever I put in the actual answer it always seems to tell me the answer is wrong, can someone please help me with this?
I am putting this code on a website that I have on WordPress as well.
Here is the code:
<!DOCTYPE HTML>
<html lang="en">
<body>
<div id="11question"></div>
<input id="answer">
<button id="check" onclick="check()">Check</button>
</body>
<script>
num5 = 500;
num6 = 500;
var operations = {
'+': function (num5, num6) {return num5 + num6;},
'-': function (num5, num6) {return num5 - num6;},
'x': function (num5, num6) {return num5 * num6;}
}
operations = ['+','-','x'][Math.min(Math.floor(Math.random()*3))];
accans= num5 + operations + num6;
num5 = Math.floor(Math.random() * 10) + 1;
num6 = Math.floor(Math.random() * 10) + 1;
operations = ['+','-','x'][Math.min(Math.floor(Math.random()*3))];
accans= num5 + operations + num6;
document.getElementById("11question").innerHTML = num5 + operations + num6;
function newquestion() {
document.getElementById('answer').value = "";
document.getElementById('answer').style.backgroundColor = "white";
num5 = 500;
num6 = 500;
var operations = {
'+': function (num5, num6) {return num5 + num6;},
'-': function (num5, num6) {return num5 - num6;},
'x': function (num5, num6) {return num5 * num6;}
}
operations = ['+','-','x'][Math.min(Math.floor(Math.random()*3))];
accans= num5 + operations + num6;
num5 = Math.floor(Math.random() * 10) + 1;
num6 = Math.floor(Math.random() * 10) + 1;
operations = ['+','-','x'][Math.min(Math.floor(Math.random()*3))];
accans= num5 + operations + num6;
document.getElementById("11question").innerHTML = num5 + operations + num6;
}
function check() {
answer = document.getElementById('answer').value;
if (accans == answer) {
document.getElementById('answer').style.backgroundColor = "green";
setTimeout(newquestion, 1500);
}
else if (accans != answer) {
document.getElementById('answer').style.backgroundColor = "red";
setTimeout(newquestion, 1500);
}
}
</script>
</html>