The monsterHealth update has been placed as requested in an if block that has the condition isMonsterHit as requested by the tutor prompt. This if block has been added after a previous if statement. Does the question expect the monsterupdate to be placed within the previous if statement or?
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
function attack() {
text.innerText = "The " + monsters[fighting].name + " attacks.";
text.innerText += " You attack it with your " + weapons[currentWeaponIndex].name + ".";
health -= getMonsterAttackValue(monsters[fighting].level);
healthText.innerText = health;
monsterHealthText.innerText = monsterHealth;
if (health <= 0) {
lose();
} else if (monsterHealth <= 0) {
if (fighting === 2) {
winGame();
} else {
defeatMonster();
}
}
if (isMonsterHit){
monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;
}
}
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 150
Reset the challenge step. And update your existing line number 185 that has monsterHealth variable assignment. By adding an if statement around it with the condition isMonsterHit
No, you are not calling the function isMonsterHit within the if condition. You only have reference to isMonsterHit. Make that function reference to a call to the function by adding () Infront of it.
Remember the if () braces should be still there along the function call.