}
//EDIT THIS FUNCTION
function stop(count){
//WRITE YOUR CODE HERE
var result = document.getElementById('result');
if (count === targetInt){
result.innerText = "Congrats, you got it!"
} else if (count > targetInt) {
result.innerText = (`Ow no, you were ${count - targetInt} off`)
} else {
result.innerText = (`Ow no, you were ${targetInt - count} off`)
}
}
//main
setTargetInt();
spin()
//HINT: ONLY EDIT THE SPIN() AND STOP() FUNCTIONS
//globals
var pushed = false //Has the stop button been pushed - false is default
var targetInt; //The target number to stop the wheel on
var spinningElem = document.getElementById('spinning'); //The spinning number
//event listener
document.getElementById("buttonPressed").addEventListener("click", buttonPressed);
//When the stop button is pushed
function buttonPressed(){
pushed = true;
}
//set the target Int
function setTargetInt(){
var targetElem = document.getElementById('targetNum');
targetInt=Math.floor(Math.random() * 101)
targetElem.innerHTML = targetInt;
}
//sleep const
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
//EDIT THIS FUNCTION
const spin = async () => {
let count = 0;
while(pushed === false){
spinningElem.innerText = (`Spining Wheel: ${count + 1}`)
count++;
if(count === 101){
count = 0;
}
await sleep(75)
}
stop(count);