-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecap.js
125 lines (96 loc) · 2.4 KB
/
recap.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
122
123
124
125
/// Datatypes
/*
- Number = Integers + Floats
- String => "just text"
- Boolean => true || false (on and off)
- Arrays => Lists
- Objects => dictonary (python name) => key/value pairs.
- undefined + null + NaN (Not a Number)
*/
console.log(Number("4") + 1);
// Boolean operators;
/*
AND - &&
OR - ||
negate (NOT) == !
*/
const teacherIsHere = true;
const isItTen = true;
const isItWeekend = false;
const classStarts = teacherIsHere && isItTen && !isItWeekend;
const weAreFree = !teacherIsHere || !isItTen || isItWeekend;
console.log("are we free?", weAreFree);
// to run some code on a certain condtion (side-effects)
if (weAreFree) {
console.log("Relaxing"); // runs if true
//sendEmail(); // side-effect (run some code);
} else {
console.log("Studying"); // runs if false
}
// to assign a certain value depending on a condition;
const message =
!teacherIsHere || !isItTen || isItWeekend ? "Relaxing" : "Studying";
console.log("Status", message);
// Intro to arrays and objects;
const averageAge = (student1.age + student2.age + student3.age) / 3;
console.log("average age", averageAge);
// Arrays
// Lists
// 0 1 2 3 4
const staff = ["Matias", "Karla", "Wouter", "Maria", "Zuzana", "Alex"];
// console.log("names of staff", staff);
// what do we usually want to do in a list?
// 1. get a certain element
const secondStaffMember = staff[1];
// console.log("second", secondStaffMember);
// 2. how many elements I have in the list?
console.log("how many staff members?", staff.length);
// question: Get the last element of the array:
console.log(staff.length - 1);
// console.log(staff[0]);
// 3. Iterate over the list and do something for each element.
// for tomorrow.
const student1 = {
name: "Maria",
id: 1,
age: 28,
group: 61,
onsite: true,
};
const student2 = {
name: "Swen",
id: 1,
age: 32,
group: 61,
onsite: true,
};
const student3 = {
name: "Alex",
id: 1,
age: 48,
group: 61,
onsite: true,
};
// .find => find elements in the array
// .filter => filter the list based on a condition
// .map =>
const staffList = [
{
name: "Karla",
age: 28,
onsite: false,
},
{
name: "Matias",
age: 18,
onsite: true,
},
{
name: "Swen",
age: 48,
onsite: false,
hobbies: ["archery", "gaming"],
},
];
const newStaffList = [...staffList, { name: "Wouter" }];
console.log("get the age of Matias", staffList);