//event listener
button.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 () => {
while(counter <= 100 && !pushed){
counter++
spinningElem.textContent = counter
await sleep(200)
}
stop();
}
//EDIT THIS FUNCTION
function stop(){
if(counter == targetInt) {
result.textContent = "Good Job mate!!!"
} else {
result.textContent = `Oops!!! Sorry. You are off by ${Math.abs(targetInt-counter)} Please
try again`
}
}
//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
var button = document.getElementById("buttonPressed")
let result = document.getElementById('result');
let counter = 0