--- title: Use the Conditional (Ternary) Operator --- ## Use the Conditional (Ternary) Operator ### Problem explanation: _Use the `conditional operator` in the `checkEqual` function to check if two numbers are equal or not. The function should return either true or false._ #### Hint 1 Remember that the "traditional" `if...else` syntax can be re-written using the conditional operator (`condition ? statement if true : statement if false;`) > _try to solve the problem now_ > ## Spoiler alert! **Solution ahead!** ## Code solution: ```javascript function checkEqual(a, b) { return a === b ? true : false; } ``` ยท Run code at [repl.it](https://repl.it/@AdrianSkar/Basic-JS-Ternary-operator). ### Code explanation - The function checks if the `condition` before the interrogation sign (`?`) is true, and if so, executes the `true` statement. Otherwise, it returns `false`. ### Resources - ["Conditional (ternary) operator" - *MDN JavaScript reference*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)