document.getElementById("buttonPressed").addEventListener("click", buttonPressed);
//When the stop button is pushed
function buttonPressed(){
clearInterval(spin)
stop(count,targetInt);
}
//set the target Int
function setTargetInt(){
var targetElem = document.getElementById('targetNum');
targetInt=Math.floor(Math.random() * 101)
targetElem.innerHTML = targetInt;
}
function myCount(){
if(count > 100){
count = 0;
}
spinningElem.innerHTML = count
count++
}
function stop(count,targetInt){
var result = document.getElementById('result');
count = count - 1
if ((count) == targetInt ){
result.innerHTML = "You Win"
}else{
result.innerHTML = `You are ${targetInt - count} numbers away`;
}
console.log(count-1)
}
//main
let spin = setInterval(myCount,100)
setTargetInt();
spin;
//globals
var pushed = false //Has the stop button been pushed - false is default
var targetInt; //The target number to stop the wheel on
let count = 0;
var spinningElem = document.getElementById('spinning'); //The spinning number
//event listener