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

Tell us what’s happening:

i did the decrement inside the if statement still not working.

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

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)+                  currentWeapon--;    
  } 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() + " breaks.";

  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36

Challenge Information:

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

You placed it in the wrong if statement.

here is the if statement

The reason why it needs to be in that if statement is because if your weapon breaks, then the currentWeapon value should adjust

i am stuck here .
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. question number 154

Decrement the value of currentWeapon in your if statement after your update text.innerText in a new line.
Example:

variableName--;

@Nitin

i have already completed the problem while ago but still thanks for your time

Actually you doesn’t said it to us before, that’s you completed the challenge. BTW your welcome and happy Coding.
@Nitin

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