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

Tell us what’s happening:

Hello,

I am writing to ask for your assistance in identifying the issue with my code. As you may be aware, the larger and more complex the code, the more challenging it can be to ensure its correct processing without errors. Unfortunately, I have encountered another instance where my code has failed the test run, causing it to fail.

Could you please help me identify the reason for this failure? I would greatly appreciate any insights or suggestions you may have. Thank you for your attention to this matter.

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[currentWeaponIndex].name + ".";
  health -= getMonsterAttackValue(monsters[fighting].level);
  
  if (isMonsterHit()) {
    monsterHealth -= weapons[currentWeaponIndex].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() <= 0.1 && inventory.length !== 1) {
    text.innerText += " Your " + inventory.pop() + " breaks.";
    currentWeaponIndex--;
  }
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 OPR/114.0.0.0

Challenge Information:

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

Learning to describe problems is hard, but it is an important part of learning how to code. Can you try to describe the issue you are having?

What is the hint you are getting? do you have trouble matching it with your code?

Also, the more you say, the more we can help!

1 Like

Hi @Dennis-code153

You should not modify your existing if statement.

Try removing the 0

Happy coding

2 Likes

Thank you very much. Your advice has helped me really and this isn’t a problem any more.

2 Likes

Yes, the code is too long and this is a real problem to make it without any mistakes or errors. Yes , I can say a lot about the code that it is too long to make it without any error or any mistake. Yes, I can talk long and hard about the length of the code and the problems with its correct coding, and I am glad that you are ready to listen to me and really help me.

1 Like

To be honest, I have never seen you talk about the code. Next time you ask for help, maybe try to do that!

2 Likes

Of course, next time I will write only about the code and how difficult and incomprehensible it is for me. Thank you for your feedback. I understand that describing the issues I’m facing is crucial for effective communication and problem-solving. In the future, I’ll focus on providing detailed explanations of the specific challenges I’m encountering when asking for assistance.

I appreciate your willingness to help and look forward to improving my ability to articulate these issues clearly. Rest assured, from now on, my requests for support will include thorough descriptions of the code-related problems I’m experiencing.

Once again, thank you for guiding me towards better practices.

1 Like