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

Tell us what’s happening:

Hello. Something is wrong in my code. Please help me.

function getMonsterAttackValue(level, xp) {
    const hit = (level * 5) - Math.floor(Math.random() * xp);
    console.log(hit);
    return hit;
}

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function getMonsterAttackValue(level, xp) {
    const hit = (level * 5) - Math.floor(Math.random() * xp);
    console.log(hit);
    return hit;
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 OPR/114.0.0.0

Challenge Information:

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

Hi

Remove your console log. Also you weren’t asked to add xp as a parameter to the function.

Here it is:

function getMonsterAttackValue(level) {
    const hit = (level * 5) - Math.floor(Math.random() * 100);
    return hit;
}

What next should I do for its correcting?

You seem to have changed what was there originally in the hit variable. Reset the lesson to how it was and try again. just put return hit and remove console log. There should not be any other changes.

The task is to return a value of hit, but the value of hit is what’s in parentheses:

function getMonsterAttackValue(level) {
    const hit = (level * 5) - Math.floor(Math.random() * 100);
    return = (level * 5) +(Math.floor(Math.random() * 100);
}

Am I right?

Hi
This bit is now wrong:

const hit = (level * 5) - Math.floor(Math.random() * 100);

Can you reset to get it how it was at the start of 148 and try again?

You had this bit right:

return hit;

Your hit variable has changed from what it was.

After reseting it is:

function getMonsterAttackValue(level) {
  const hit = (level * 5) - (Math.floor(Math.random() * xp));
  console.log(hit);
}

That’s it. Work on that. Just do what is asked, no other changes, and remove console log.

1 Like

Thanks, it is a real solution of the problem.I had a basic and advanced understanding of algebra, geometry, and the basics of analysis in mathematics, but I was confused by an equation that I wanted to solve using two conventional mathematical methods.

1 Like