So Rory McCrossan gave me this code for an health bar:
But if i whould want to make something that damages the player i dont know how to make a way to do that as some problems like the text not updating and taking more damage than it should take.
let textNode = document. createTextNode("Health: "); document. body. appendChild(textNode);
let health = 100;
const textNode4 = document.createTextNode(health);
const updateHealthUi = (el, health) => el.textContent = health;
document.body.appendChild(textNode4);
document.addEventListener('keydown', e => {
e.preventDefault();
switch (e.key) {
case "e":
health = Math.min(100, ++health);
break;
case "q":
health = Math.max(0, --health);
break;
}
updateHealthUi(textNode4, health);})
if you can make a code for the health bar to make it so that i can make a way to take damage pls do
New contributor
Bruh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1