Use Multiple Conditional (Ternary) Operators

Tell us what’s happening:
It says to Use multiple conditional operators in the checkSign function to check if a number is positive, negative or zero. but I’m not very good with them I’ve been stuck on this for nearly an hour trying stuff so I’d apreciate some help.

Your code so far


function checkSign(num) {
 return (num === num) ? "positive" : (num > num) ? "negative" : "zero"; 
}

checkSign(-12);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/use-multiple-conditional-ternary-operators

Ok I’ll start by looking up how to check if a number is positive thanks for the help.

return (num > 0) ? “positive” : (num < 0) ? “negative” : “zero”;

This is the solution for this exercise.

5 Likes

its not passing the exercise

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

checkSign(10);
This is the solution.

I have solved this, but have a question as I was failing on capitalization. If “negative” and positive" are in “”, doesn’t that make them strings, thus literal text?

How did you get this because i dont get 10 as postive and -12 as negitive but i get zero back.

ive got it just a type error in my strings.