Learn-basic-javascript-by-building-a-role-playing-game - Step 148

Step 148

If you play the game in its current state you might notice a bug. If your xp is high enough, the getMonsterAttackValue function will return a negative number, which will actually add to your total health when fighting a monster!

In getMonsterAttackValue, change return hit to a ternary operator that returns hit if hit is greater than 0, or returns 0 if it is not.

Here is an example of returning a value based on condition with a ternary:

return condition ? true : false;

help me find what went wrong please.
here’s my code:

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

please read carefully, it says “if hit is greater than 0”, not “greater or equal”

I was able to figure it out, Thank you so much.

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