Skip to content

Commit d65d375

Browse files
committed
Add article about else
1 parent 6aedea1 commit d65d375

2 files changed

Lines changed: 59 additions & 3 deletions

File tree

‎conditional/else.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Else
2+
3+
There is also an `else` clause that will be applied every time the first condition isn’t true. This is very powerful if you want to react to any value, but single out one in particular for special treatment:
4+
5+
```javascript
6+
var umbrellaMandatory;
7+
8+
if(country === 'England'){
9+
umbrellaMandatory = true;
10+
} else {
11+
umbrellaMandatory = false;
12+
}
13+
```
14+
15+
The `else` clause can be join with another `if`, lets remake the example from the previous article:
16+
17+
```javascript
18+
if(country === 'England') {
19+
...
20+
} else if(country === 'France') {
21+
...
22+
} else if(country === 'Germany') {
23+
...
24+
}
25+
```
26+
27+
28+
---
29+
30+
Fill up the value of `name` to validate the `else` condition.
31+
32+
```js
33+
var name =
34+
35+
if (name == "John") {
36+
37+
} else if (name == "Aaron") {
38+
// Valid this condition
39+
}
40+
```
41+
42+
```js
43+
var name = "Aaron";
44+
45+
if (name == "John") {
46+
47+
} else if (name == "Aaron") {
48+
// Valid this condition
49+
}
50+
```
51+
52+
```js
53+
assert(name == "Aaron");
54+
```
55+
56+
---

‎conditional/if.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ var weather;
88
var food;
99
var currency;
1010

11-
if(country === 'England'){
11+
if(country === 'England') {
1212
weather = 'horrible';
1313
food = 'filling';
1414
currency = 'pound sterling';
1515
}
1616

17-
if(country === 'France'){
17+
if(country === 'France') {
1818
weather = 'nice';
1919
food = 'stunning, but hardly ever vegetarian';
2020
currency = 'funny, small and colourful';
2121
}
2222

23-
if(country === 'Germany'){
23+
if(country === 'Germany') {
2424
weather = 'average';
2525
food = 'wurst thing ever';
2626
currency = 'funny, small and colourful';

0 commit comments

Comments
 (0)