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

Tell us what’s happening: I am stuck and I have tried everything but my code still doesnt work. What am I doing wrong? I have commented out the second because its just a different order. I dont know what to change anymore.

Your code so far

monsterHealth -= weapons[currentWeapon].power + (Math.floor(Math.random() * xp) + 1);

// (Math.floor(Math.random() * xp) + 1) + monsterHealth -= weapons[currentWeapon].power;


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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge Information:

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

You are technically doing this correctly, you’ve just added an extra pair of parentheses that aren’t needed and the tests aren’t expecting and thus the tests think you did it incorrectly. Remove the outermost pair of parentheses and you will pass.

I understand why you added them. It does seem to make sense to group the Math.floor function and the 1 you are adding to it in parentheses since they are working together to create the random number that you want. But since you are only adding all of these numbers together you don’t technically need them since it doesn’t matter what order you add these things together.

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