Как создать генератор математических вопросов с помощью JavaScript?Html

Программисты Html
Anonymous
Как создать генератор математических вопросов с помощью JavaScript?

Сообщение Anonymous »

По сути, я пытаюсь создать веб-сайт, включающий в себя генератор вопросов по математике (для учащихся 2 или 3 классов), и когда я запускаю код, он дает мне все: вопрос, кнопку проверки, область вывода, но всякий раз, когда я ввожу фактический ответ, мне всегда кажется, что ответ неправильный. Может ли кто-нибудь помочь мне с этим?
Я также размещаю этот код на своем веб-сайте на WordPress.
Вот код:






Check



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);
}
}




Подробнее здесь: https://stackoverflow.com/questions/654 ... javascript

Вернуться в «Html»