We don’t want a player’s only weapon to break. The logical AND operator checks if two statements are true.
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.
Please I’m stuck here:
if (isMonsterHit() && inventory.length !== 1) {}
This is what i did and it didnt pass
WARNING
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
You will need to take an additional step here so the code you wrote presents in an easy to read format.
Please copy/paste all the editor code showing in the challenge from where you just linked.
Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 157
one is no data type, you will get an undefined when you try this. You are comparing to data type number. You also are still in the wrong if statement there is one down below describing the weapon breaking…
We don’t want a player’s only weapon to break. The logical AND operator checks if two statements are true.
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.
Here’s my code:
if (Math.random() <= .1 && inventory.length != 1) {
text.innerText += " Your " + inventory.pop() + " breaks.";
currentWeapon–;