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

Tell us what’s happening:

I can’t get this one right. I have tried restarting multiple times, and adding and deleting if statements and moving them around. The hint tells me to add a new if statement inside my else if block. Haven’t I done that?

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 -= monsters[fighting].level;
  monsterHealth -= weapons[currentWeaponIndex].power + Math.floor(Math.random() * xp) + 1;
  healthText.innerText = health;
  monsterHealthText.innerText = monsterHealth;
  if (health <= 0) {
  } else if (monsterHealth <= 0) {
    if(fighting === 2) {

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

Challenge Information:

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

this is the assignment:
Back to your attack function - inside the else if block, create another if and else statement. If the player is fighting the dragon (fighting would be 2), call the winGame function. Move the defeatMonster() call to the else block.

For this step, you will need to use the strict equality (===) operator to check if fighting is equal to 2.


else does not have a condition, so you can go ahead and remove the brackets.
And your attack funtion closing curly bracket, }, is missing, add it in at the end.

I hate the fact that this is the solution…

1 Like

Don’t worry too much about it, stuff like this happens. Happy coding!

1 Like