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

Tell us what’s happening:

Hello everyone, kindly walk me through this. How do I use ternary to return 0 if hit is not greater than?

My code is below;

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

}code here

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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15

Challenge Information:

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

Hi! Look carefully at the instructions: “or returns 0 if it is no.” You have “default _score”

This line is not needed, the function stops after executing the first return

Hey Thanks for your reply. I tired this below but it didn’t work.

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

}

No need for “returns”, you are already in the return statement.
And remove semicolon at the end, it may cause error

Appreciate your patient, I tried this but it didn’t work. What are my missing?

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

}
1 Like

Where’s the second value for the ternary?

I don’t know how to go about it.

Ok, can you try to put the second value in? Something should be after the :

Appreciate for your patience.