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

Tell us what’s happening:

I can’t understand where is the issue with my if else statement.

### Your code so far

function attack() {
if (health <= 0) {
lose();
} else if (monsterHealth <= 0) {
if(monsters[fighting] === 2){
winGame();
}else{
defeatMonster();
}
}
}

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 (Windows NT 10.0; Win64; x64) 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 139

I guess I would question exactly what this is checking.

check if fighting is equal to 2

hi there @cr1812, please create your own post to ask for help

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

1 Like

pkdvalis,

your answer was exactly what the exercise was asking. Thank you

2 Likes

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