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

This is what i was told to do " Use the += operator to add " Your <weapon> breaks." , with a space in front of Your , to the end of text.innerText . Replace <weapon> with the last item in the inventory array using inventory.pop() , which will remove the last item in the array AND return it so it appears in your string."

please am i doing anything wrong


  let lastItem = inventory.pop();
  text.innerText +=  " Your " + lastItem ;

### Your browser information:

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36</code>

### Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 153
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-basic-javascript-by-building-a-role-playing-game/step-153

You could try doing this in one line, and I don’t see the end of the sentence there.

I’ve edited your code for readability. 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 (').

Your code works, as you can see it logs the item popped, however, the tests being run are looking for your strings to match what it expects. Open the console window that’s provided and follow the test results. This will allow you to identify the issue.

So, I’m also having issues with this step, but I’m not creating a new variable for the last item. That doesn’t seem necessary, since the .pop() automatically selects and removes the last item inherently.

But the submit button says that :
Sorry, your code does not pass. Keep trying.

You should add " breaks.", with a space in front of it, to the end of your string.

but I have that in my string?

Here’s the section of my current 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.";
  }
}

I tried inspecting the console, it says :
// running tests You should add

" breaks."

, with a space in front of it, to the end of your string. // tests complete

I’m not sure if that’s …I think that’s just copy pasta for what the hint is saying, right? Really confused, and I wanted to get this little project finished this morning, but I’m kinda stuck at this point.

Any help and or insight is greatly appreciated, thanks
jer

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.