Currently, I am trying to make code for a game when, on pointerdown, a progress tag slowly depletes over time and, on pointerup, the progress bar slowly refills from the value it stopped on.
This is my current working logic:
HTML:
<progress id="air" max="100" value="100"></progress>
Javascript:
// Javascript
var air = document.querySelector('#air').value;
function drowning(){
if (air <= 0){
console.log("You have drowned");
} else {
air--;
}
};
addEventListener('pointerdown', function() {
var losingair = setInterval(drowning, 250);
});
addEventListener('pointerup', function() {
clearInterval(drowning);
setInterval(gainingair, 200);
function gainingair() {
if (air = 100) {
clearInterval(gainingair);
}
else {
air++;
}
}
});