Is there a way to continuously run the top set interval whenever I lift my finger from the space key? When I try using the key up event, it only executes that function once. I'm not sure how to implement if/else logic when adding an event listener.
setInterval(function (e) {
r--;
}, 10);
document.addEventListener("keydown", function (e) {
console.log(r);
if (e.keyCode === 32) {
setInterval(function (e) {
r++;
if (r > 240) {
r = 200;
}
}, 100);
}
});