* 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
883 B
883 B
title
| title |
|---|
| Use the Conditional (Ternary) Operator |
Use the Conditional (Ternary) Operator
Problem Explanation
- You need to write a function named
checkEqual, which checks if the two parameters are equal. - If the parameters are equal,
Equalis to be returned elseNot Equalshould be returned.
Hints
Hint 1
Use ternary operator to check for equality.
Solutions
Solution 1 (Click to Show/Hide)
function checkEqual(a, b) {
return a === b ? "Equal" : "Not Equal";
}
Code Explanation
- A function
checkEqualis declared, it accepts two parameters in variablesaandb. - The
returnstatement would return the value of the evaluated ternary expression. - The ternary expression checks if
aandbare equal or not and returnsEqualorNot Equalrespectively.