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"; 


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:

First your code checks if num === num. That is always going to be true (unless num is NaN), so your function is going to return “positive” for every test.

First see if you can create the same function using if/else if/else statements. Once you get that working, then try using ternary operators.

Currently, your algorithm seems to be incorrect. You need to ask these two basic questions:

  1. How do you check if a number is positive?
  2. How to you check if a number is negative?

Once you have code that checks for these conditions, then any other number passed into the function must be zero.

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.


its not passing the exercise

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

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.