-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSwitchStatement.js
More file actions
33 lines (30 loc) 路 880 Bytes
/
Copy pathSwitchStatement.js
File metadata and controls
33 lines (30 loc) 路 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var firstName = 'John';
var job = 'instructor';
switch (job) {
case 'teacher':
case 'instructor':
console.log(firstName + ' teaches kids how to code.');
break;
case 'driver':
console.log(firstName + ' drives an uber in Lisbon.');
break;
case 'designer':
console.log(firstName + ' designs beautiful websites.');
break;
default: // if above case's false then default will execute
console.log(firstName + ' does something else.');
}
var age = 56;
switch (true) {
case age < 13:
console.log(firstName + ' is a boy.');
break;
case age >= 13 && age < 20:
console.log(firstName + ' is a teenager.');
break;
case age >= 20 && age < 30:
console.log(firstName + ' is a young man.');
break;
default:
console.log(firstName + ' is a man.');
}