-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsession3.js
82 lines (63 loc) · 1.38 KB
/
session3.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
// for LOOOOOOOOP
for (let i = 0; i < 10; i++) {
console.log(`For loop is going on here ${i} time!`);
}
//While Loop
let i = 0;
while (i < 10) {
console.log(`While loop is going on here ${i}time!`);
i++;
}
// loop in array
for (let i = 0; i < todos.length; i++) {
console.log(todos[i].text);
}
//better way
for (let todo of todos) {
console.log(todo.id);
}
//forEach, map, filter
//forEach
todos.forEach(function (todo) {
console.log(todo.text);
});
//MAP
const todoText = todos.map(function (todo) {
return todo.isCompleted;
});
console.log(todoText);
//Filter
const todoCompleted = todos.filter(function (todo) {
return todo.isCompleted === true;
});
console.log(todoCompleted);
// const todoCompleted = todos.filter(function(todo)
// {
// return todo.isCompleted == true;
// }).map(function(todo)
// {
// return todo.text;
// });
// console.log(todoCompleted);
//conditionals
const zx = 10; //Assign
if (zx === 10) {
console.log('zx is 10');
} else {
console.log('zx is not 10');
}
//Iternally Opraters like short hand is statements
const q = 10;
const color1 = q > 10 ? 'Red' : 'Blue';
console.log(color1);
//switch
const x1 = 20;
const color = x1 > 10 ? 'Red' : 'Blue';
switch (color) {
case 'Red':
console.log('Color is red');
break;
case 'Blue':
console.log('color is not red or blue');
break;
}