I am trying to make a text adventure that will output the correct console log statement based on a specific input. I want it so that if the goblin does enough attack damage so that the player's defense is less than 0 that the console log will print out "The Goblin did" x amount of "damage!". Here is my variable list at the top of the code:
//player stats
var atk= 1;
var def= 1;
var hp= 10;
var mp= 0;
var block= 1;
var magic= 0;
//goblin stats
var gobAtk= [3,4,5];
var gobDef= 1;
var gobHp= 5;
var gobMagDef= 0;
var rand= Math.floor(Math.random()* gobAtk.length);
At the bottom of my code a specific if/else condition is called as long as the goblin's hp (var gobHp) has not gone down to zero after the player attacks the goblin in the earlier section of the code. Here it is:
else {
def-=rand;
if(def<0) {
hp-=Math.abs(rand);
console.log("The Goblin did"+ " "+ Math.abs(rand)+ " "+ "Damage!");
if(hp<=0) {
console.log("The Goblin defeated you! You died");
console.log("Game Over.");
}
}
else {
console.log("The Goblin did 0 damage!");
}
}
But no matter how many times I run through the code the console log always prints out "The Goblin did 0 damage!" even if the goblin's atk minuses the player's def to less than 0. If the player's def is less than 0 the console log should print out the correct amount of damage.
Aucun commentaire:
Enregistrer un commentaire