Formatting examples, added example based on note (#21186)
would like some feedback on my extra example :)
This commit is contained in:
@ -73,16 +73,23 @@ const num = someCondition ? 1 : 2;
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Using** `else if`:
|
**Using** `else if`:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
if (x < 10){
|
// Categorising any number x as a small, medium, or large number
|
||||||
return "Small number";
|
if (x < 10)
|
||||||
}else if (x < 50){
|
return "Small number";
|
||||||
return "Medium number";
|
else if (x < 50)
|
||||||
}else if (x < 100){
|
return "Medium number";
|
||||||
return "Large number";
|
else if (x < 100)
|
||||||
}else {
|
return "Large number";
|
||||||
flag = 1;
|
else {
|
||||||
return "Invalid number";
|
flag = 1;
|
||||||
}
|
return "Invalid number";
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Using** `if` **alone**:
|
||||||
|
```javascript
|
||||||
|
// This function can also act as a Boolean
|
||||||
|
if (x < 30) {
|
||||||
|
return "true";
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user