Learn Basic JavaScript by Building a Role Playing Game - Step 157

Tell us what’s happening:

The directions say to modify the if statement to include && inventory.length !==1 when I add it the auto coder says do not modify the if statement.

Your code so far

if (Math.random() <= 0.1 && inventory.length !== 1) {
text.innerText += " Your " + inventory.pop() + " breaks.";
currentWeapon–;
}


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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

What is the hint you are getting?

Step 157

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 is an example of an if statement with two conditions:

if (firstName === "Quincy" && lastName === "Larson") {

}

Those are the instructions. If you aren’t passing then you should be getting a hint under the Check Your Code button. What does that hint say?

Sorry, your code does not pass. Hang in there.

You should not modify your existing if statement.

I will admit, this hint is not that great, but what it is trying to tell you is that you should not modify anything about the if statement that was already there. You should only add to it. You have modified something that you didn’t need to and the tests don’t like it. I would reset the step to get the original code back and then be careful to only add the new stuff to the if statement. Don’t change anything that is already there.

Thankyou kindly I will try that.

Wow that worked, same exact code. Thankyou so very much !

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.