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`:
|
||||
|
||||
```javascript
|
||||
if (x < 10){
|
||||
return "Small number";
|
||||
}else if (x < 50){
|
||||
return "Medium number";
|
||||
}else if (x < 100){
|
||||
return "Large number";
|
||||
}else {
|
||||
flag = 1;
|
||||
return "Invalid number";
|
||||
}
|
||||
// Categorising any number x as a small, medium, or large number
|
||||
if (x < 10)
|
||||
return "Small number";
|
||||
else if (x < 50)
|
||||
return "Medium number";
|
||||
else if (x < 100)
|
||||
return "Large number";
|
||||
else {
|
||||
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