Home > Software design >  Looping until the health runs out - Node.js
Looping until the health runs out - Node.js

Time:01-27

I am creating a JS CLI Game.

I need a loop that will automatically decrease health on both the player and the enemy and it won't stop until one of their's healths becomes 0 or less.

while (playerHealth > 0 || enemyHealth > 0) {
      if (playerHealth > 0 || enemyHealth > 0) {
        headerColor("Round", colors.blue, colors.green)

        let decreaseHealth1 = randomDecreaseHealth()
        playerHealth - decreaseHealth1
        console.log("Ouch ! You lost "   decreaseHealth1)

        let decreaseHealth2 = randomDecreaseHealth()
        enemyHealth - decreaseHealth2
        console.log("Nice hit. Enemy lost "   decreaseHealth2)
      } else if (playerHealth <= 0) {
        console.log("Damn, you lost.            
  • Related