multiple ternary operator challenge - add note about code readability (#36269)
* fix multiple ternary operator challenge * Fix a typo in multiple ternary operator challenger Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * Fix a typo in multiple ternary operator challenge #2 Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
committed by
Parth Parth
parent
acbc07e0ff
commit
8b40da02a3
@ -26,6 +26,16 @@ function findGreaterOrEqual(a, b) {
|
||||
|
||||
The above function can be re-written using multiple <code>conditional operators</code>:
|
||||
|
||||
```js
|
||||
function findGreaterOrEqual(a, b) {
|
||||
return (a === b) ? "a and b are equal"
|
||||
: (a > b) ? "a is greater"
|
||||
: "b is greater";
|
||||
}
|
||||
```
|
||||
|
||||
However, this should be used with care as using multiple <code>conditional operators</code> without proper indentation may make your code hard to read. For example:
|
||||
|
||||
```js
|
||||
function findGreaterOrEqual(a, b) {
|
||||
return (a === b) ? "a and b are equal" : (a > b) ? "a is greater" : "b is greater";
|
||||
|
Reference in New Issue
Block a user