2018-10-12 15:37:13 -04:00
---
title: Use the Conditional (Ternary) Operator
---
2019-03-02 05:10:29 +05:30
 Remember to use < a > **`Read-Search-Ask` **</ a > if you get stuck. Try to pair program  and write your own code 
2018-10-12 15:37:13 -04:00
## Use the Conditional (Ternary) Operator
2019-03-02 05:10:29 +05:30
###  Problem Explanation:
* You need to write a function named `checkEqual` , which checks if the two parameters are equal.
* If the parameters are equal, `true` is to be returned else `false` should be returned.
##  Hint
Use ternary operator to check for equality.
2018-10-12 15:37:13 -04:00
2018-11-21 18:36:11 +01:00
> _try to solve the problem now_
2019-03-02 05:10:29 +05:30
## Spoiler Alert!
2018-11-21 18:36:11 +01:00
2019-03-02 05:10:29 +05:30

2018-11-21 18:36:11 +01:00
**Solution ahead!**
2018-10-12 15:37:13 -04:00
```javascript
function checkEqual(a, b) {
2018-11-21 18:36:11 +01:00
return a === b ? true : false;
2018-10-12 15:37:13 -04:00
}
```
2018-11-21 18:36:11 +01:00
2019-03-02 05:10:29 +05:30
### Code Explanation:
2018-11-21 18:36:11 +01:00
2019-03-02 05:10:29 +05:30
* A function `checkEqual` is declared, it accepts two parameters in variables `a` and `b` .
* The `return` statement would return the value of the evaluated ternary expression.
* The ternary expression checks if `a` and `b` are equal or not and returns `true` or `false` respectively.