I have problem with displaying true/false after submiting an answer to question.
I need to display true when answer is true e.g.( 14+1=15 true), but my code is always displaying false and never displays true. Hope you will understand my code.
p.s. to display question press answer, in start it doesn't display question.
function myfunc() {
//randomizer + - * /
var symbol;
var s = Math.floor(Math.random() * 5);
if (s === 1) {
symbol = '+';
}
if (s === 2) {
symbol = '-';
}
if (s === 3) {
symbol = '*';
}
if (s === 4) {
symbol = '/';
}
//first num randomizer
var firstnum = Math.floor(Math.random() * 100);
//sec num randomizer
var secnum = Math.floor(Math.random() * 100);
document.getElementById('demo').innerHTML = firstnum + symbol + secnum;
//answer filter
var input = document.getElementById('input').value;
var testanswer;
if (s === 1) {
testanswer = firstnum + secnum;
}
if (s === 2) {
testanswer = firstnum - secnum;
}
if (s === 3) {
testanswer = firstnum * secnum;
}
if (s === 4) {
testanswer = firstnum / secnum;
}
//test answerer
if (testanswer === input) {
document.getElementById('atbilde').innerHTML = 'true';
}
else {
document.getElementById('atbilde').innerHTML = 'false';
}
}
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script type="application/javascript" src="test.js"></script>
</head>
<body>
<p id="demo"></p>
<input id="input" type="text">
<button id="mybt" type="button" onclick="myfunc()">submit</button><br>
<p id="atbilde"></p>
</body>
</html>