Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save periakteon/d8bd0d52170977638e6237d29487c9d8 to your computer and use it in GitHub Desktop.
Save periakteon/d8bd0d52170977638e6237d29487c9d8 to your computer and use it in GitHub Desktop.
FreeCodeCamp: Use Multiple Conditional (Ternary) Operators (Solution)
function checkSign(num) {
// eğer 0'dan büyükse, "positive" stringi döndür ( if )
return num > 0 ? "positive"
// eğer 0'dan küçükse, "negative" stringi döndür (else if)
: num < 0 ? "negative"
// kalan tüm durumlarda "zero" döndür ( else )
: "zero"
}
console.log(checkSign(10));
// positive
console.log(checkSign(-10));
// negative
console.log(checkSign(0));
// zero
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment