the URL for the game is Arena RPG Game
The layout is pretty self explanatory, so please check it out a bit before replying.
Now, on to the issue.
After the character, and beast are created, when I click on "Fight!" an alert will display the damage done by my character, and the beast. Say for example that my character does 7 Damage, and the beast does 1 damage. The result will leave my HP at -23, and the beast HP at -11(hypothetically). I have placed if statements that are supposed to set the Damage to 0 if the result is a negative number, and the fight should end when either the character's HP, or beast's HP reaches 0. The way the it is playing out though, one or both of them are a negative number after one round, and I know that the math is wrong. Please help. I've been working for days to get this fixed so I can move on to adding experience, and gold when the fight is won. I just don't see where the logic error is.
Here is the fight function where all the problems are. If you want to see more of the code, just visit the link, and view source.
charFightHP = charHP;
beastFightHP = beastHP;
fightTrue = 1;
charDmg = charStr - beastDef;
beastDmg = beastStr - charDef;
beastName = document.getElementById("theBName").innerHTML;
if (charDmg < 0)
charDmg = 0;
else if (beastDmg < 0)
beastDmg = 0;
while (fightTrue != 0)
if (charFightHP > 0 && beastFightHP > 0)
charFightHP = beastDmg - charFightHP;
beastFightHP = charDmg - beastFightHP;
alert("You do "+charDmg+" damage to "+beastName+". "+beastName+" does "+beastDmg+" damage to you.");
document.getElementById("theHP").innerHTML = charFightHP;
document.getElementById("theBHP").innerHTML = beastFightHP;
fightTrue = 0;
if (beastFightHP < 0 && charFightHP > 0)
if (charFightHP < 0)
alert("You are dead");
All the variables for the stats are defined in the full program so that's not the issue. The numbers display correctly, until the math operation for the fight is executed.
Thank you in advance to anyone willing to help me debug this.