-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
187 lines (149 loc) · 3.44 KB
/
main.js
File metadata and controls
187 lines (149 loc) · 3.44 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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
console.log("main.js is connected!");
console.log("script loaded!");
alert("Hello World");
console.log("Hello World");
console.error("this is an error");
// Strings, number, boolean, null, undefined
const name = "john";
const age = 30;
const rating = 4.5;
const isCool = true;
// const x = null;
// const y = undefined;
let z;
console.log(typeof age);
// concatenation;
console.log("My name is " + name + " and i am " + age);
const s = "Technology, Computers, It, Code,";
console.log(s.split(","));
// Arrays - variables that holds multiple values
const fruits = ["Apples", "Oranges", "pears", 10, true];
fruits[3] = "grapes";
fruits.push("mangoes");
fruits.unshift("strawberries");
fruits.pop();
console.log(Array.isArray("fruits"));
console.log(fruits);
// // const person = {
// firstName: "Kareemah",
// lastName: "Ahmad",
// age: 30,
// hobbies: ["music", "movies", "sports"],
// address: {
// street: "50 main st",
// city: "Tambari",
// state: "GRA",
// },
// };
// console.log(person.firstName, person.lastName);
// console.log(person.hobbies[1]);
const todos = [
{
id: 1,
text: "Take out Trash",
isCompleted: true,
},
{
id: 2,
text: "Meeting with boss",
isCompleted: true,
},
{
id: 3,
text: "Dentist appointment",
isCompleted: false,
},
];
console.log(todos);
const todoJSON = JSON.stringify(todos);
console.log(todoJSON);
//for
for (let i = 0; i < 10; i++) {
console.log("For Loop Number: $(i)");
}
//While
let i = 0;
while (i < 10) {
console.log("While Loop Number: $(i)");
i++;
}
for (let i = 0; i < todos.length; i++) {
console.log(todos[i].text);
}
for (let todo of todos) {
console.log(todo);
}
// for Each, map, filter
todos.forEach(function (todo) {
console.log(todo.text);
});
// for Each, map, filter
const todoText = todos.map(function (todo) {
return todo.text;
});
const todoCompleted = todos.filter(function (todo) {
return todo.isCompleted === true;
});
console.log(todoCompleted);
console.log(todoText);
//conditional
const x = 6;
const y = 11;
if (x == 10) {
console.log("x is 10");
} else if (x > 10) {
console.log("x is greater than 10");
} else {
console.log("x is less than 10");
}
if (x > 5 && y > 10) {
console.log("x is more than 5 or y is more than 10");
}
const o = 9;
const color = "green";
switch (color) {
case "red":
console.log("color is red");
break;
case "blue":
console.log("color is blue");
break;
default:
console.log("color is NOT red or blue");
}
// function
const addNums = (num1 = 1, num2 = 1) => {
console.log(num1 + num2);
};
addNums(5, 5);
// constructor function
// function Person(firstName, lastName, dob) {
// this.firstName = firstName;
// this.lastName = lastName;
// this.dob = new Date(dob);
// Person.prototype.getBirthYear = function () {
// return this.dob.getFullYear();
// };
// }
// Person.prototype.getFullName = function () {
// return "${this.firstName} ${this.lastName}";
// };
//Class
class Person {
constructor(firstName, lastName, dob) {
this.firstName = firstName;
this.lastName = lastName;
this.dob = new Date(dob);
}
getBirthYear() {
return this.dob.getFullYear();
}
getFullName() {
return "${this.firstName} ${this.lastName}";
}
}
// instantiate object
const person1 = new Person("kareema", "Ahmad", "4-3-1980");
const person2 = new Person("Yusrah", "Dauda", "3-6-1999");
console.log(person2.getFullName());
console.log(person1);