Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

765 B
Raw Blame History

title
title
Use Multiple Conditional (Ternary) Operators

Use Multiple Conditional (Ternary) Operators


Solutions

Solution 1 (Click to Show/Hide)

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

Heres a solution:

In the function body we need to add multiple conditional operators - as in our lesson:

{
  return num > 0 ? "positive" : num < 0 ? "negative" : "zero";
}

In this way, function can check if a number is positive, negative or zero.

Heres a full solution:

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