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

Tell us what’s happening:

How do I add Math. Floor()

Your code so far

function defeatMonster() {

gold = gold += level * 6.7

Math.Floor(gold);

}

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 129

You going to have one line of code here: gold += Math.floor(const name[variable] . level * 6.7) use one of the const names and one of let variables at the top of this code block.

3 Likes

function defeatMonster() {

gold += level * 6.7;

Math.Floor(gold)

}

I also tried
function defeatMonster() {
Math.Floor(gold += level * 6.7);

}

This is my latest code

function defeatMonster() {
gold += Math.Floor(monsters[fighting].level * 6.7);
}

Tell us what’s happening:

I haven’t figured out how to use Math.Floor

Your code so far

function defeatMonster() {
Math.Floor(gold += level * 6.7);

}

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 129

Math.floor just rounds a number down to the nearest integer. So if you have the number 5.0900989034598 it will return 5.

I would concentrate on this part first:

“…set gold equal to gold plus the monster’s level times 6.7

You are on the right track, but you need to think a little more about how you get the monster’s level. How did you get the monster’s name in the dodge function?

Then, once you have that figured out, you want want to round the “result” down using Math.floor. What is the “result” in this case? It’s the number you get from multiplying the monster’s level by 6.7. That’s the value you want to pass into Math.floor, and then you can add it to your gold.

function defeatMonster() {
Math.Floor(gold += monsters[fighting].level * 6.7);

}

Is this closer. I still not understanding how to use Math.Floor. I understand what is does.

It worked when I lover cased the f in floor.

Yes, this is closer. You are accessing the monster’s level correctly now.

Just keep in mind, it’s a simple function that takes in a number and returns a number. So you want to pass it a number. That number in this case is the result of multiplying the monster’s level by 6.7. You seem to be passing in more than that.

This looks pretty good to me, but you should check the spelling on the function name. Math is an object and thus starts with a capital letter by convention. Method/function names usually start with lowercase.

Mine is not working sadly

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