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

Tell us what’s happening:

I cannot understand how to use the logical AND operator.

### Your code so far:

if (isMonsterHit( )  &&  inventory.length !== 1) {
    monsterHealth -= weapons[currentWeapon].power + Math.floor(Math.random() * xp) + 1;    
  } else {
    text.innerText += " You miss.";
  }

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 (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

This challenge is about the player’s only sword 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."

But you do have a good example of an logical AND operator.

Happy learning. :slight_smile:

1 Like

Here is an example of the logical AND operator.

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

}

It allows us to use multiple conditions in an if statement.

And as for where the code is supposed to be used.

We want to use it in the code block where the player’s weapon breaks.

1 Like

Thanks I understood that I was applying the code on the wrong destination.

1 Like

Can u tell me what you mean by applying the code to the wrong destination, i tried to solve this but still didn’t work. So far my code:

if(weapons.length > 1 && inventory.length > 1){ }

1 Like

hey @nurularifin83

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

2 Likes

Thank u so much for your suggestion.

1 Like

You don’t need to create a new function but add second function using logical And operator. Add second function using (&&) operator in the already present weapon break if condition you already wrote in step 154.

im also here at 157 but im so confused cannot code it still… ant help ?

hey @talshai656

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.