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

Tell us what’s happening:

Since you subtracted health from the player, you need to check if the player’s health is less than or equal to 0 . If it is, call the lose function.

I think I have the right code but I dont know someone please help

Your code so far

if (numbers.includes(guess) && health <= 0) {
    text.innerText += "Right! You win 20 gold!";
    gold += 20;
    goldText.innerText = gold;
  } else {
    text.innerText += "Wrong! You lose 10 health!";
    health -= 10;
    healthText.innerText = health;
    lose()
  }
}

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

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

2 Likes

Hey, you just need to remove the entire if statement, its only going to take three things to pass. Also you need to remove those quote marks the editor wont except that style.

It is asking for a nested if inside the else block and not to change the condition of the outer if statement.


I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

The forum does that when the code isn’t formatted properly. You can see they are correct now after the edit. The same happens with other stuff so if you see unformatted code it often looks like it has syntax issues.

1 Like

my bad next time I will make it more readble but thank you