Skip to content

Instantly share code, notes, and snippets.

@Nhoya
Last active December 23, 2016 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nhoya/76acb1bbfc9dd1b2fdf7f830fbcd8822 to your computer and use it in GitHub Desktop.
Save Nhoya/76acb1bbfc9dd1b2fdf7f830fbcd8822 to your computer and use it in GitHub Desktop.
Telegram Math Battle Game Solver
function solver(){
var num1 = Number(document.getElementById('task_x').innerHTML);
var num2 = Number(document.getElementById('task_y').innerHTML);
if( oldnum1 !== num1 || oldnum2 !== num2){
var operation = document.getElementById('task_op').innerHTML;
var fake_result = document.getElementById('task_res').innerHTML;
var result = true;
if (operation === '×'){
result = (num1 * num2);
}
if (operation === '+'){
result = (num1 + num2);
}
if (operation === '–'){
result = (num1 - num2);
}
if (operation === '/'){
result = (num1 / num2);
}
if (result == fake_result){
console.log(num1 + operation + num2 + "=" +result + " " + "true");
document.getElementById('button_correct').click();
}
else{
console.log(num1 + operation+ num2 + "=" +result + " " +"false");
document.getElementById('button_wrong').click();
}
oldnum1 = num1;
oldnum2 = num2;
}
}
var oldnum1 = 0;
var oldnum2 = 0;
var loop_var = setInterval(solver, 100);
//clearInterval(loop_var)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment