Last active
July 5, 2019 13:48
-
-
Save SukkaW/c31ff4bfe83e379c4389b46d2aa14f6d to your computer and use it in GitHub Desktop.
Be the best in the Math Battle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function math() { | |
let x = parseInt(document.getElementById('task_x').innerHTML, 10); | |
let y = parseInt(document.getElementById('task_y').innerHTML, 10); | |
let op = document.getElementById('task_op').innerHTML; | |
let res = parseInt(document.getElementById('task_res').innerHTML, 10); | |
let choose = { | |
true: () => document.getElementById('button_correct').click(), | |
false: () => document.getElementById('button_wrong').click() | |
} | |
if (op === '+') { | |
if (x + y === res) { | |
choose.true(); | |
console.log(`${x} + ${y} = ${res}`); | |
} else { | |
choose.false(); | |
console.log(`${x} + ${y} != ${res}`); | |
} | |
} else if (op === '–') { | |
if (x - y === res) { | |
choose.true(); | |
console.log(`${x} - ${y} = ${res}`); | |
} else { | |
choose.false(); | |
console.log(`${x} - ${y} != ${res}`); | |
} | |
} else if (op === '×') { | |
if (x * y === res) { | |
choose.true(); | |
console.log(`${x} * ${y} = ${res}`); | |
} else { | |
choose.false(); | |
console.log(`${x} * ${y} != ${res}`); | |
} | |
} else if (op === '/') { | |
if (x / y === res) { | |
choose.true(); | |
console.log(`${x} / ${y} = ${res}`); | |
} else { | |
choose.false(); | |
console.log(`${x} / ${y} != ${res}`); | |
} | |
} | |
} | |
function stop() { | |
let choose = { | |
true: () => document.getElementById('button_correct').click(), | |
false: () => document.getElementById('button_wrong').click() | |
} | |
setInterval(() => { | |
choose.false(); | |
}, 1); | |
} | |
setInterval(math, 60); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment