Reputation: 33
For some reason doesItHit
and doTheyHit
always seem to execute, whilst dealDamage
does nothing to the global variable.
var hitPercentage=Math.floor(Math.random() * 101) + 1
function doesItHit(){
if(toHit * hitPercentage >= enemyEvasion){itHits = true}
else("You miss.")
}
function doTheyHit(){
if(enemyToHit * (Math.floor(Math.random() * 101) + 1) >= evasion){enemyToHit = true}}
function dealDamage(){enemyHealth= enemyHealth-lasers;}
function recieveDamage(){health= health - enemyLasers;}
function playerTurn(){
doesItHit();
if (itHits===true){
dealDamage()
console.log("You deal "+ lasers + " points of damage to the enemy.")
lasersFired=false
}
}
Upvotes: 0
Views: 40
Reputation: 8975
You didn't form correct expression so your dealDamge will never deal the damage due to wrong expression:
enemyHealth= enemyHealth;-lasers;
You this:
enemyHealth= enemyHealth-lasers;
Upvotes: 0
Reputation: 48415
It is because your code doesn't actually change anything. You have an extra semi-colon within dealDamage
that you don't want.
Try this:
function dealDamage(){
enemyHealth = enemyHealth - lasers;
}
(Assuming you want to subtract the value of lasers
from enemyHealth
)
On a side note, your recieveDamage
function won't do anything either, but it is not clear as to what you intend for that so I cannot offer any suggestions.
Upvotes: 5