forked from CodeYourFuture/HTML-CSS-Coursework-Week1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathggg.js
More file actions
49 lines (38 loc) · 1.31 KB
/
ggg.js
File metadata and controls
49 lines (38 loc) · 1.31 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
/*
1) Define an array containing the 3 persons defined below.
2) Return an array of the person names (hint: use map).
3) Filter the persons to return an array with the person younger than 28 years old (hint: use filter).
*/
let person1 = {
name: "Alice",
age: 25
};
let person2 = {
name: "Bob",
age: 30
};
let person3 = {
name: "John",
age: 20
};
/*
DO NOT EDIT ANYTHING ABOVE THIS LINE
WRITE YOUR CODE BELOW
*/
let persons = [person1, person2, person3]
// Complete here
let personNames = persons.map(item => item.name) // Complete here
console.log()
let personsYoungerThan28YearsOld = persons.filter(function(item) {
if (item.age < 28)
return item
}) // Complete here
/*
DO NOT EDIT ANYTHING BELOW THIS LINE
*/
console.log("Question 1: array defined with 3 persons -> ",
(persons[0] === person1 && persons[1] === person2 && persons[2] === person3) ? 'Passed :)' : 'Not yet :(');
console.log("Question 2: array containing the person names -> ",
(personNames[0] === "Alice" && personNames[1] === "Bob" && personNames[2] === "John") ? 'Passed :)' : 'Not yet :(');
console.log("Question 3: array containing the persons younger than 28 years old -> ",
(personsYoungerThan28YearsOld[0] === person1 && personsYoungerThan28YearsOld[1] === person3) ? 'Passed :)' : 'Not yet :(');