Tell us what’s happening:
So I’m kinda stuck here… The hint says to add " breaks."; to the end of my string, but I have? The console says the same thing, I’m not entirely sure if that’s because it’s replicating what the hint is saying, I think that’s what it is, but it’s not giving me a specific syntax error or any other error code that I can see. I’ve looked over my code pretty meticulously, I don’t see any typos or missing characters.
So far, from what I’ve tried to learn about this is in that code, if my weapon is Sword, it would change the text to “Your Sword breaks.” and remove that item, Sword, from my inventory, and return that value, updating the inventory content to be what it was, minus Sword. The format and syntax is correct for me to implement that? I’m not missing any like… brackets or quotation marks or anything else?
It doesn’t seem like it to me, but maybe I’m oblivious to something, idk.
Thanks for any help || insight,
jer
Your code so far
function attack() {
text.innerText = "The " + monsters[fighting].name + " attacks.";
text.innerText += " You attack it with your " + weapons[currentWeapon].name + ".";
health -= getMonsterAttackValue(monsters[fighting].level);
if (isMonsterHit()) {
monsterHealth -= weapons[currentWeapon].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() <= .1) {
text.innerText += " Your " + inventory.pop().name + " breaks.";
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0
Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 153