-
Notifications
You must be signed in to change notification settings - Fork 1
/
lesson05.js
61 lines (50 loc) · 910 Bytes
/
lesson05.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
// Loops and conditions
console.log((4 > 5))
console.log(('asddf'.length > 'asdf'.length))
console.log(((4 < 5) || (5 > 6)))
console.log((4 > 5))
console.log((false))
function ifs (x) {
if (x > 2) {
console.log('woo')
} else if (x < -1) {
console.log('hoo')
} else {
console.log('boo')
}
}
ifs(3)
ifs(-2)
ifs(0)
function cases (text) {
switch (text) {
case 'yes':
return 'NO!'
case 'no':
return 'YES!'
default:
return 'Why'
}
}
console.log(cases('yes'))
console.log(cases('no'))
console.log(cases('other'))
var b = 0
while (b < 5) {
console.log(b)
b++
}
do {
console.log(b)
b--
} while (b > 0)
for (var i = 0; i < 10; i++) {
console.log('My favorite number is ' + i)
}
var names = ['juan', 'pedro', 'luis']
for (i in names) {
console.log(names[i])
}
names.forEach(function (element) {
console.log('My name is ' + element)
}, this)