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

Tell us what’s happening:

adding return value of inventory.pop() to the " your " string

Your code so far

  text.innerText += " Your " + brokenWeapon + " breaks."; 
}

}
}

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/122.0.0.0 Safari/537.36

Challenge Information:

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

Tell us what’s happening:

Your code so far

if (Math.random() <= .1) {
if (inventory.length > 0) {
let brokenWeapon = inventory.pop();
text.innerText += " Your " + brokenWeapon + " breaks.";

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/122.0.0.0 Safari/537.36

Challenge Information:

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

Hi @1douglas

The instructions did not ask you to create a new variable.
Remove the newly created variable.
Then replace brokenWeapon with the expression for the last item in the inventory array.

Happy coding

Hi there, almsost done!
In this step you need the last item in the inventory array, so use inventory.pop() to remove the last item in the array and return it.
Hence no need for brokenWeapon here

The code is not still working i don’t Understant why?kindly assist

if (inventory.length > 0) {
const brokenWeapon = inventory.pop();
text.innerText += " Your " + brokenWeapon + " breaks. ";
}

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/122.0.0.0 Safari/537.36

Challenge Information:

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

Hi @1douglas

The .pop() method does two things:

  1. accesses the last item in an array
  2. removes that item from an array

You can use that code directly in the .innerText property of text

So no need to declare the brokenWeapon variable.

Happy coding

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