FCC Ternary - in-line if else
by vanduzled
JavaScript
function checkEqual(a, b) {
return a == b ? "Equal" : "Not Equal";
}
checkEqual(1, 2);
// Use the conditional operator in the checkEqual function to check if two numbers are equal or not. The function should return either the string Equal or the string Not Equal.
// Use Multiple Conditional (Ternary) Operators
function checkSign(num) {
return ( num >= 1 ) ? "positive"
: ( num < 0 ) ? "negative"
: "zero";
}
checkSign(10);
// The function should return positive, negative or zero.