I'm creating a webpage and I decided to try to get you back to the start automatically if it takes a certain amount of time without clicking the screen. I tried to do so but when I enter the page no matter how much it touches the screen the time does not reset and the alert appears anyway. The webpage is also loading and does not load all the content. Here is the code I currently have:
var startTime = new Date();
document.addEventListener('DOMContentLoaded', function(){
var seconds = 1;
while (seconds < 5) {
endTime = new Date();
var timeDiff = endTime - startTime; //in ms
// strip the ms
timeDiff /= 1000;
// get seconds
var seconds = Math.round(timeDiff);
console.log(seconds + " seconds");
setTimeout(() => {}, 1000); // Like time.sleep
}
alert("Touch the screen!")
})
document.addEventListener("click", function() {
console.log("Hello")
startTime = new Date()
});
Thank you!