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

Tell us what’s happening:

Hey there, I’m struggling to solve this… can anyone explain the problem in my code?

Your code so far

function attack() {
text.innerText = “The " + monsters[fighting].name + " attacks.”;
text.innerText += " You attack it with your " + weapons[currentWeapon].name + “.”;
health -= monsters[fighting].level;
monsterHealth = weapons[currentWeapon].power + (Math.floor(Math.random() * xp)+1);

}

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; rv:122.0) Gecko/20100101 Firefox/122.0

Challenge Information:

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

Please talk to us about what has you confused or stuck on this step in your own words. Thanks

In my code above, I’m still getting error. as my understanding to the instruction I should add the result of mathfloor in the result of monster[currentHealth].power and i assign to variable monsterHealth. But still got error.

It looks like you might have an extra set of brackets that could be causing your error?

I’d tried like this… monsterHealth = weapons[currentWeapon].power + Math.floor(Math.random() * xp)+1;

but still got error… and console returned You should add to the weapon[currentWeapon].power.

Math.floor(Math.random() * xp) + 1; ---- looks correct, but in the given example it shows “monsterHealth -=” ?

1 Like

thank you… I’ve got… almost 1hr tried to solve this.