-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavascript_2.js
More file actions
212 lines (170 loc) · 3.48 KB
/
Copy pathjavascript_2.js
File metadata and controls
212 lines (170 loc) · 3.48 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
////arrow function
const ask = (question, yes, no) => {
if(confirm(question)){
return "we are here already"
}else{
return "we die here if need be"
}
}
///ITERATION -- LOOP :
//(for
// normal for
// -for of
// -for in
//while
//Do While )
///FOR
for (let i=0; i<100; i++) {
console.log("hello world")
}
let newArr = [34, 56, 21, 89]
for (let i=0; i<newArr.length; i++){
console.log(`${i} - ${newArr[i]}`) ////=> 0 - 34, 1 - 56, 2 - 21, 3 - 89
}
c
let str = "The man in the kitchen wants meats"
let res = ''
let skipped = ''
for(let i= 0; i<str.length; i++){
if(str.at(i) === 'n'){
skipped = skipped + str.at(i)
continue
}
res = res + str.at(i)
}
console.log(skipped)
for(let i= 0; i< str.length; i++){
console.log(str[i])
}
///FOR OF
let arr =[ 23, 45, 78]
for(let i of arr){
console.log(i)
}
///FOR OF
let numbers = [34,56,7,9]
for(let number of numbers){
console.log(number)
}
///FOR IN
let numberObj ={
a: "Aduke",
b: "Asake",
c: "Anike"
}
for(let name in numberObj){
console.log(numberObj[name])
}
///Write a function that prints multiplication of 2
function multiplication(x){
for(let i= 1; i< 12; i++){
console.log(`${i} * ${x} = ${i * x}`)
}
}
multiplication(5)
///OBJECT
let users =[{
firstName: "Sam",
lastName: "Dole",
age: 21,
grades: [ {
year1: 3.20,
year2: 3.40,
year3: 6.80,
}, 18, 14, 17],
interest: ["computers","Books"]
},
{
firstName: "Mustapha",
lastName: "Sanni",
age: 21,
grades: [ {
year1: 3.20,
year2: 3.40,
year3: 6.80,
}, 18, 14, 17],
interest: ["computers","Books"]
}
]
console.log(users[0].grades[0].year1)
console.log(users[0].grades[0])
////
const grades = [
{
date: "2018-12-13",
grade: 14
},
{
date: "2018-12-15",
grade: 18
}
]
function getNumberOfTestsTaken(grades){
const result = grades.filter(item => item.grade>=0)
return result.length
}
console.log(getNumberOfTestsTaken(grades))//2
///
const sampleUsers =[
{
id : 1,
firstName: "Abayomi",
lastName: "Ajao"
},
{
firstName: "sam",
lastName: "Benard"
}
]
function logName(sampleUsers){
sampleUsers.forEach(item =>{
console.log(`${item.firstName} ${item.lastName}`)
})
}
let arr1 = [1,2,3,4,5,6]
for(let item of arr1 ){
console.log(item)
}
////OBJECT KEYS
function giveObjectKey(a){
return Object.keys(a)
}
console.log(giveObjectKey({id : 1, firstName: "Abayomi", lastName: "Ajao"}))
const obj ={
name: "Niyi",
age: 23,
gender: "Male",
likes: ['football', 'ping-pong', 'money', 'jolof'],
friends:[{name:"Ola", gender: "male", likes: ['ping-pong', 'money', 'jolof']},
{},
{name:"Player", gender: "male", likes: ['ping-pong', 'coding', 'jolof']}]
}
console.log(obj.friends[2].likes[1])
///OBJECT VALUE
///OBJECT KEYS
const obj ={
name: "Niyi",
age: 23,
gender: "Male",
likes: ['football', 'ping-pong', 'money', 'jolof'],
friends:[{name:"Ola", gender: "male", likes: ['ping-pong', 'money', 'jolof']},
{},
{name:"Player", gender: "male", likes: ['ping-pong', 'coding', 'jolof']}]
}
console.log(obj.friends[2].likes[1])
console.log(Object.keys(obj)[1])
console.log(Object.values(obj)[3])
////SET TIMEOUT : makes the request come out in 5 seconds
console.log("A")
console.log("B")
setTimeout(()=>{
console.log("come out of here")
},5000)
console.log("C")
////PROMISE
const _data = [
{name:"Ayodeji Ayokele",
},
{},
{}
]