Tell us what’s happening: Once again, very vague instructions. Set monsterHealth to monsterHealth minus the power of the player’s current weapon. Remember you have the currentWeapon variable and the power property.
OK…instruction say “Set monsterHealth to monsterHealth - power of player’s current weapon”:
This is what the instructions are telling to do. I’m sorry, but the instructions need to be very explicit for beginners, those with ZERO programming knowledge to follow along. I have an idea what’s going on, but these instructions are so vague that the answer is not remotely close to the actual instructions.
### Your code so far
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 Edg/120.0.0.0
Challenge Information:
Learn Basic JavaScript by Building a Role Playing Game - Step 122
The goal for this challenge is to use the subtraction assignment operator to set monsterHealth equal to monsterHealth minus the power of the current weapon you have equipped.
In this challenge, you have a bunch of weapons already. Right now currentWeapon is sort of the location of your selected weapon. You know how in videogames that you have a bunch of weapons on a selection screen, currentWeapon is kinda like the number of the weapon you’re using. Only the first weapon starts at position zero.
Subtraction assignment is a fancy way of subtracting a value from some variable and immediately setting it equal to the result.
I think the first sentence in the instructions accurately reflects the answer.
“Set monsterHealth to monsterHealth minus the power of the player’s current weapon.”
This tells you that you will need to subtract the power value of the current weapon from the monster’s health, which is exactly what the solution does.
The instructions give you the name of the variable for the monster’s health (which is monsterHealth), but what they don’t do is tell you exactly how to get the power value of the current weapon. They do hint to how to do this in the second sentence. But they are relying on you to understand what variable is used to keep track of the current weapon and how to get the power value from that variable.
This is what makes programming somewhat challenging. It’s not enough to understand the syntax and rules of the language. You also have to understand how the code is organized and what it is doing. So in this case, you need to understand where the player’s weapons are being stored (i.e. which variable they are stored in) and how the information for each weapon is being stored (i.e. what data structure is being used to store the information for each weapon). Only when you understand this will the answer really be apparent.
So you need to be able to answer these questions?
What variable are the player’s weapons stored in?
How are you keeping track of the player’s current weapon?
How do you access a specific property of a weapon?
Hopefully the variable names you have been using are good enough to help you answer these questions. Also, you already have a similar example in the attack function when you added the current weapon’s name to the innerText that you can use as an example.
So yes, the instructions aren’t explicitly telling you exactly what to do, but they do tell you enough to pass the step. They are just relying on you to understand how the data is stored in order to solve it.
I will say that this project might be a little too ambitious for an introduction to JS. I don’t think any of the JS is too difficult, but I think it might be a little too big and thus slightly overwhelming for a first timer just learning JS.