JavaScript step 155 challenge

Hi everyone!

please am not understanding what to do here. please can anyone help me out in javaScript step 155?

here is my code below:

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

can you give a link to the step?

you are missing the second term of the comparison here, your code will not work without it

I don’t know how go about this . I have been on this this since three days and am unable to solve it.

I need an assistant to help me out

Did you fix what @ilenia pointed out above?

&& inventory.length !==)

This is not valid JS. You need something on the right side of !==. What do the instructions say you should have there?

If you have made changes to your code and it still isn’t working then you need to paste your updated code in here so we can see what you did.

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Here is my current code and yet to pass.

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

“Use the logical AND operator && to add a second condition to your if statement.”

Instead of adding a second condition to the existing if statement you have created a whole new if statement. You want to add to this if statement:

if (Math.random() <= .1) {

I tried this before I was not passed.

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

This is almost correct. Both @ilenia and I have pointed out the error with your code in posts above. You should reread our posts.

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

what about this last code you posted?

Honestly, the more I try solving challenge the more am getting more confused

inventory.length !==) This ‘)’ is Wrong.
Should be inventory.length !== x ) where x is some number.

Yet to pass

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

you should not put x there, you need to write an appropriate number

how to know the appropriate number? you need to make sure that the last weapon doesn’t break, how many weapons are in the inventory if it is the last weapon?

still not passed.

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

if the inventory length is 3, that means you still have 3 weapons in your ownership, and at that point none can break. instead you need to make sure that the last weapon remaining will not break. The last one.

Am still unable to pass.

my code below;

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

I think there is some logic you are missing here:
you need to make sure that the last weapon doesn’t broke, and protect it from the code that breaks a weapon. 3.3 is not a possible length for an array, as the number of elements is always going to be an integer.

If you count how many weapons you have when you have only the last weapon, it will be a count of 1. So you need to avoid breaking the weapon when you have one weapon in the inventory. That means that you need to check that the inventory length is not 1 to allow for the weapon to break.

honestly speaking am total lost here. I don’t know how to go about this challenge