freeCodeCamp Challenge Guide: Use Multiple Conditional (Ternary) Operators

Use Multiple Conditional (Ternary) Operators


Solutions

Solution 1 (Click to Show/Hide)
function checkSign(num) {
  return num > 0 ? "positive"
    : num < 0 ? "negative"
    : "zero";
}

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

25 Likes