Tell us what’s happening:
Hello,
I am writing to ask for your assistance in identifying the issue with my code. As you may be aware, the larger and more complex the code, the more challenging it can be to ensure its correct processing without errors. Unfortunately, I have encountered another instance where my code has failed the test run, causing it to fail.
Could you please help me identify the reason for this failure? I would greatly appreciate any insights or suggestions you may have. Thank you for your attention to this matter.
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);
if (isMonsterHit()) {
monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;
} else {
text.innerText += " You miss.";
}
healthText.innerText = health;
monsterHealthText.innerText = monsterHealth;
if (health <= 0) {
lose();
} else if (monsterHealth <= 0) {
if (fighting === 2) {
winGame();
} else {
defeatMonster();
}
}
if (Math.random() <= 0.1 && inventory.length !== 1) {
text.innerText += " Your " + inventory.pop() + " breaks.";
currentWeaponIndex--;
}
}
// 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/128.0.0.0 Safari/537.36 OPR/114.0.0.0
Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 157