Tell us what’s happening:
Clearly my code is incorrect but i can’t think of other solutions.
Step 129
In your defeatMonster
function, set gold
equal to gold
plus the monster’s level times 6.7
. You can get the monster’s level with the level
property.
Here is an example of setting num
to num
plus 5
* 8
: num += 5 * 8
. Use Math.floor()
to round the result down.
### Your code so far
function defeatMonster() {
gold += Math.floor(monsters.level * 6.7);
}
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 129
Learn to Code — For Free
Please Tell us what’s happening in your own words.
Learning to describe problems is hard, but it is an important part of learning how to code.
Also, the more you say, the more we can help!
1 Like
ILM
December 22, 2023, 8:09pm
3
Jubibani:
monsters.level
monsters
is an array, it doesn’t have a level property, you need to get the level
of the single monster. Look for example at the function right above this one,
function dodge() {
text.innerText = "You dodge the attack from the " + monsters[fighting].name;
}
how does it get the name of the monster?
1 Like
oh okay. thank you. i will do that next time.
I apologize, I’m still getting the hang of it.
the example below got access to the name of the monster because of this part of code:
monsters[fighting].name;
it accessed the “monsters” array then the [fighting] which was a declared variable and then the “name”.
I exchanged. the “name” for “level”. and it worked.
Thank you!
1 Like
system
Closed
June 22, 2024, 8:19am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.