Quantcast
Channel: Active questions tagged crash - Stack Overflow
Viewing all articles
Browse latest Browse all 7191

JavaScript code keeps crashing, no idea why

$
0
0

I have made a small web game, however, when I press one of the buttons, it crashes the JavaScript. I have no idea why, I have checked the code thoroughly but I cannot find what is going on.

The section of code that is causing the problems is below.

function update() {  .  .  .  if (inBattle) {    showById("attack");    showById("escape");    if (currentFloor == 0) {      currentFloor += 1;      currentEnemy = randomElement(enemies[0]);    }    document.getElementById("inBattle").innerHTML = "You are in battle!";    let battleStats = currentEnemy.ascii +"\n\n\n" +"You are fighting: " + currentEnemy.name +"\nHealth: " + currentEnemy.hp +" hp / "+ currentEnemy.max +" hp\nWeapon: " + currentEnemy.weapon.name+"\nDamage: " + currentEnemy.weapon.damage +"\nArmour: "+ currentEnemy.armour.name +" (" + currentEnemy.armour.armourValue +" pts)\n\nYou:\nHealth: " + health +" hp / " + maxHealth+" hp\nWeapon: " + currentWeapon.name +"\nDamage: "+ currentWeapon.damage +"\nArmour: " + currentArmour.name+" (" + currentArmour.armourValue +" pts)\n\n";    document.getElementById("battleStats").innerHTML = battleStats;    while (enemiesPassed < enemiesPerFloor) {      while (currentEnemy.isAlive()) {}      enemiesPassed += 1;      money += currentEnemy.drop;      currentEnemy = randomElement(enemies[currentFloor - 1]);    }    currentFloor += 1;    if (currentFloor > maxFloor) {      currentFloor = maxFloor;    }    currentEnemy = randomElement(enemies[currentFloor - 1]);  } else {    hideById("attack")    hideById("escape")    document.getElementById("inBattle").innerHTML = "You are not battling anything right now.";    document.getElementById("battleStats").innerHTML = "";  }}

Sorry for the giant block of code. Pls don't downvote if the solution is obvious and I haven't spotted it


Viewing all articles
Browse latest Browse all 7191

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>