Why does my enemy attack after it is dead?(Javascript) -


     function battle(){     //user turn     alert("it's turn!");     var user_move = prompt("type 1 use fireball, 2 use lightning strike, or 3 earthquake");     if(user_move == 1){       var r = math.round(math.random()*(dmg.length-1));       alert("you did "+dmg[r]+" damage enemy!");       enemy_hp = enemy_hp - dmg[r];     }     else if(user_move == 2){       var r = math.round(math.random()*(dmg.length-1));       alert("you did "+dmg[r]+" damage enemy!");       enemy_hp = enemy_hp - dmg[r];     }     else if(user_move == 3){       var r = math.round(math.random()*(dmg.length-1));       alert("you did "+dmg[r]+" damage enemy!");       enemy_hp = enemy_hp - dmg[r];     }     alert("your enemy has "+enemy_hp+"hp");     //enemy turn     alert("now enemys turn!");     var = math.round(math.random(enemy_attack.length-1));     var r = math.round(math.random()*(dmg.length-1));     alert("you enemy used "+enemy_attack[a]+"\nand did "+enemy_dmg[r]+" damage you!");     hp = hp - enemy_dmg[r];     alert("you have "+hp+"hp!");     //if still living keep battling     if(hp > 0 && enemy_hp > 0){       battle();     }     else if(hp <= 0){       alert("you lost d:");     }     else if(enemy_hp <= 0){       alert("you win :d!");     }   }   battle(); 

i trying make fun little js battle game when kill enemy has 1 final attack , can kill when dead. how fix it?

place enemy attack code inside of if statement

if (enemy_hp > 0){    //enemy attack code } else alert("you win :d!"); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -