Use Multiple Conditional (Ternary) Operators need help :)

Tell us what’s happening:

Your code so far

function checkSign(num) {
  function findGreaterOrEqual (a, b){
      return (a === b) ? "a and b are equal" : (a > b) ? "a is greater" : "b is greater";


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:

That’s what you need to do…

Use multiple conditional operators in the checkSign function to check if a number is positive, negative or zero.

function checkSign(num) {
return num==0?“zero”:num>0?“positive”:“negative”;

By the way it’s not recommendable to create a function inside of another function.

1 Like

I don’t understand the way to do it.

Did you understand what you need to do in this challenge?
Do you know how a ternary operator works?

That’s the point of you doing this challenge, you need to understand how things work.

not understand it :slight_smile:

I see, what didn’t you understand specifically? It might be the case to repeat the lesson about ternary operators or you might try to watch some video on YouTube that will explain you in details how the ternary operator works.

here are two examples:

is a = 2 ? yes, it’s 2 : no, it’s another number
a==2? "it's 2" : "it's another number"

is a = 2 ? yes, it’s 2 : no, is a = 3? yes, it’s 3 : no, it’s neither 2 nor 3
a==2? "it's 2": a==3? "it's 3" : "no, it's neither 2 nor 3"

PS: the ternary operator is going to return some value, so you can either store the value inside of a variable or return the value since that’s what the function is expected to do in this exercise.

i will watch some video on youtube :smile: )

You have at least one problem, maybe two.

1. You are not understanding the problem presented in the challenge Your responses are not satisfying the challenge. For example there is no response “a and b are equal” in the solution for the challenge. In the case of num is 0 you should simply return “zero”

checkSign(10); // should return "positive"
checkSign(-12); // should return "negative"
checkSign(0); // should return "zero"

The example problem and the solution are not exactly the same so copying the example into your solution without modification will not work.

In the example problem they are comparing two arguments a and b.
There are three possible responses based on the condition of a and b -

  • “a and b are equal” tested with conditional a===b,
  • “a is greater” tested with conditional a > b
  • or “b is greater” the only other possible condition

In the challenge you are comparing one argument named num against zero.
There are three possible responses in your return statement. You will need to create conditional tests to determine which of these apply to the num passed to your function.

  • “zero” - you will need to create a test conditional here
  • “positive” - and another test conditional here too
  • “negative”

2. You may or may not understand the ternary operator
Other than pasting the example solution you haven’t shown that you understand using ternary with multiple conditions. If you are unsure how that works maybe you should test your logic using if else structure first and once you are returning the correct response modify your code to use multiple ternary operators.