While loop - Infinite cycle


#1



So for this code your own adventure 2 project, im creating a simple game, but im experiencing a problem where everytime I run the following While loop, my broswer crashes. I have no clue whats wrong obviously, and Ive added console.log markers to help narrow down the problem. The first console.log never fires however a console.log that is created just before the loop does fire. Any idea what is wrong?


var monsterChoice = "Dragon"
var fighting = true;
console.log(monsterChoice);

while(monsterChoice === "Dragon") {
    console.log("While loop one");
    if(monsterChoice == "Dragon") {
        console.log("if statement");
        while (dragonHealth > 0) {
            console.log("while loop two");
            if(playerHealth <= 0) {
                fighting = false;}
            else {
                console.log("else statement");
                var playerDamage = weaponMod * playerStratMod *                             playerSkill * 5 * Math.ceil(Math.random()*5);
                console.log(playerDamage);
                var dragonDamage = dragonStratMod * 10 * monsterSkill *                     Math.floor(Math.random()*6);
                console.log(dragonDamage);
                console.log(playerDamage);
                dragonHealth -= playerDamage;
                playerHealth -= dragonDamage;
            }
        }
    } else {fighting = false
}
var fighting = false


#2

This variable is never anything else, hence the infinite loop. It has to change at some point in the program or this condition will result.


#3

My god. I cant believe I didnt notice that! Ok thanks!