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

Tell us what’s happening:

Hello everyone please I need to know how to decrement currentWeapon in this challenge. my instruction is below;

Remember that the increment operator ++ can be used to increase a variable’s value by 1. There is also a decrement operator -- that can be used to decrease a variable’s value by 1. For example :

let num = 10;
num--;
console.log(num); // Output: 9

Decrement the value of currentWeapon in your if statement, after you update the text.

Your code so far

my code is below;

  goFight();
}

function goFight() {
  update(locations[3]);
  monsterHealth = monsters[fighting].health;
  monsterStats.style.display = "block";
  monsterName.innerText = monsters[fighting].name;
  monsterHealthText.innerText = monsterHealth;
}


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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15

Challenge Information:

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

1 Like

Hi there! As said in the instructions, you have to

Decrement the value of currentWeapon in your if statement, after you update the text.

In this if statement:

  if (Math.random() <= .1) {
    text.innerText += " Your " + inventory.pop() + " breaks.";

So just put here currentWeapon variable and use a decrement operator just like how the example shows

2 Likes

Hey appreciate your guidance.

1 Like