-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcontrol-structures.js
More file actions
74 lines (60 loc) · 1.37 KB
/
control-structures.js
File metadata and controls
74 lines (60 loc) · 1.37 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// control structures -- sequence , conditional statments and loops
// conditional statements
// if else
let age = 40;
if (age > 65) {
console.log("You should be retired");
} else if (age > 18) {
console.log("Your should be working");
} else if (age > 4) {
console.log("You should be at school ");
} else {
console.log("You should be at home");
}
let age2 = 90;
if (age2 > 65) {
console.log("You should be retired");
} else if (age2 < 18) {
if (age2 < 4) {
console.log("Your should be at home/daycare ");
} else {
console.log("Your should be at school");
}
} else {
console.log("You are working");
}
// switch statement
let category = "C";
switch (category) {
case "A":
console.log("Retired");
break;
case "B":
console.log("Working");
break;
case "C":
console.log("School");
break;
default:
console.log("Daycare");
break;
}
// loops/iteration
let cars = ["CX-5", "Honda Fit", "T Probox", "Imprezza"];
// for loop
for (let start = 0; start < 900; start += 50) {
console.log("Start is at " + start);
}
// for elem in arr/object -- looping throuhg elements of an array/object
for (let car in cars) {
console.log("Execute!!");
console.log(cars[car]); // car names
}
// while loop
let number = 5;
while (number < 10) {
console.log("Excecuting !!!!!!!!");
number++;
}
console.log("Other code");
//do while loop