-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloops.js
123 lines (95 loc) · 1.71 KB
/
loops.js
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//exercice 1
var i = 0;
while (i <= 9) {
console.log("One run of the loop");
i += 2
}
//exercice 2
for (var i=0; i <=9 ; i+= 2) {
console.log("One run of the loop");
}
//exercice 3
for (var i=0; i <=100; i+=2) {
console.log(i);
}
//exercice 4
for (var i=0; i <=100; i++) {
console.log(i);
if (i % 2 === 0) {
console.log("is even")
}
else {
console.log("is odd")
}
}
//Exercise 5
var item = ["First item", "Second item", "Third item", "Fourth item"];
for (var i=0; i <= 3; i++) {
console.log(item[i]);
}
//Exercice 6
customers = [
"Albin Term",
"Anna Sandgrove",
"John Doe",
"Terrance Head",
"Yan Mock",
"Zoe Durst"
];
console.log("List of all customers : ");
for (i=0; i <= 5; i++) {
console.log(customers[i]);
}
//Exercice 7
var items = ["First item",
"Second item",
"Third item",
"Fourth item"];
for(var item of items){
console.log(item);
}
//Exercice 8
var citizen = {
"firstname" : "John",
"lastname" : "Doe",
"age" : 45,
"income" : 60000
};
citizen["sexe"]=0;
for (var key in citizen)
if (key === "sexe") {
if (citizen["sexe"]===0){
console.log(key + " " + "Male");
}
else if (citizen["sexe"]===1){
console.log(key + " " + "female");
}
}
else {
console.log(key + " " + citizen[key])
}
//Exercise 9
var citizens = [
{
"firstname" : "John",
"lastname" : "Doe"
},
{
"firstname" : "Anna",
"lastname" : "Molner"
},
{
"firstname" : "Harry",
"lastname" : "Trueman"
},
{
"firstname" : "Cecile",
"lastname" : "Mercier"
}
];
for(var citizen of citizens){
console.log("citoyen : ");
for(var key in citizen) {
console.log(key + " : " +citizen[key])
}
}