Skip to content

Instantly share code, notes, and snippets.

@SukkaW
Last active July 5, 2019 13:48
Show Gist options
  • Save SukkaW/c31ff4bfe83e379c4389b46d2aa14f6d to your computer and use it in GitHub Desktop.
Save SukkaW/c31ff4bfe83e379c4389b46d2aa14f6d to your computer and use it in GitHub Desktop.
Be the best in the Math Battle
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