Attack Messages: It first tells you that the monster is attacking and then lets you know you’re hitting back with your current weapon.
Taking Damage: Your character’s health drops depending on how powerful the monster’s attack is.
Hitting the Monster: The game checks if you land your hit. If you do, the monster takes damage based on your weapon’s power and some random boost from your experience. If you miss, the game tells you.
Updating Health: It then shows the latest health status for both you and the monster on the screen.
Winning or Losing: If your health reaches zero, you lose. If the monster’s health hits zero, you either win the game (if it’s the final boss) or advance to the next monster.
Weapon Breakage: Sometimes, your weapon might break after an attack, and you lose it from your inventory. But don’t worry, this only happens if you have more than one weapon left.
the code is not passing
the question is this:
Use the logical AND operator && to add a second condition to your if statement. The player’s weapon should only break if inventory.length does not equal (!== ) one.
Something is wrong with your code. It doesn’t match the original code given in this step. Please make your browser do a hard refresh (usually that is CTRL-f5 on windows) and then click reset.
After that add the new condition.
if (Math.random() <= 0.1 && inventory.length !== 1) {
text.innerText += " Your " + inventory.pop() + " breaks.";
currentWeaponIndex–;
}
}
it is still not passing
actually you have changed the > more than opretor to <= less than or equal opretor for the first condition. correct that and your code will pass. remember you need only more than > opretor for the fisrt condition comperison.
if (Math.random() > 0.1 && inventory.length !== 1) {
text.innerText += " Your " + inventory.pop() + " breaks.“;
currentWeaponIndex–;
}
}
it still saying " You should not modify your existing if statement.”
i got it now. you need to add the second condition carefully, that`s the fisrt condition should not been modified in any condition. now reset the challenge step and try to add the second condition carefully.