I'm currently developing a game where two players engage in combat.
Currently, I have managed to set up the system so that the player's health points (hp) are displayed as 100. However, when an event occurs causing the player to take 10 damage, instead of updating the hp bar to reflect 90, it simply concatenates and displays 10090.
How can I modify my code so that the previous value is updated rather than being appended next to it?
function player(hp, mana, stamina){
this.hp = hp;
this.mana = mana;
this.stamina = stamina;
}
function npc(hp, mana, stamina) {
this.hp = hp;
this.mana = mana;
this.stamina = stamina;
}
var alistar = new player(100, 50, 30);
var dragon = new npc(100, 50, 30);
document.getElementById("hp").innerHTML += alistar.hp;
if (0 < 1) {
alistar.hp = alistar.hp - 10;
document.getElementById("hp").innerHTML += alistar.hp;
}
Using the "=" sign to update the value works, but it removes any HTML content I had in place. I may consider creating a second div box for my HTML needs and keeping the value separate.