I would like to, when x reaches 5, exit out of a document.onkeydown function. I tried this:
var x = 0
document.onkeydown = function() {
console.log("Still running...")
x += 1
if (x >= 5) {
break
}
}
but the console says that it was an illegal break statement. I have also tried using a return
statement to exit out of the onkeydown loop, but that hasn't worked either. Do any of you know how to exit out of one of these? If so, I would very much like to know it.