-
-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathexercise.js
More file actions
90 lines (86 loc) · 1.66 KB
/
exercise.js
File metadata and controls
90 lines (86 loc) · 1.66 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
let hogwarts = [
{
firstName: "Harry",
lastName: "Potter",
house: "Gryffindor",
pet: "Owl",
occupation: "Student",
},
{
firstName: "Ron",
lastName: "Weasley",
house: "Gryffindor",
pet: "Scabbers",
occupation: "Student",
},
{
firstName: "Hermione",
lastName: "Granger",
house: "Gryffindor",
pet: "Cat",
occupation: "Student",
},
{
firstName: "Draco",
lastName: "Malfoy",
house: "Slytherin",
pet: null,
occupation: "Student",
},
{
firstName: "Cedric",
lastName: "Diggory",
house: "HufflePuff",
pet: null,
occupation: "Student",
},
{
firstName: "Severus",
lastName: "Snape",
house: "Slytherin",
pet: null,
occupation: "Teacher",
},
{
firstName: "Filius",
lastName: "Flitwick",
house: "Ravenclaw",
pet: null,
occupation: "Teacher",
},
{
firstName: "Pomona",
lastName: "Sprout",
house: "Hufflepuff",
pet: null,
occupation: "Teacher",
},
{
firstName: "Minerva",
lastName: "McGonagall",
house: "Gryffindor",
pet: null,
occupation: "Teacher",
},
{
firstName: "Albus",
lastName: "Dumbledore",
house: "Gryffindor",
pet: "Phoenix",
occupation: "Teacher",
},
];
// Task 1
function belongToGryffindor({ firstName, lastName, house }) {
if (house === "Gryffindor") {
console.log(`${firstName} ${lastName}`);
}
}
// Task 2
function teachersWithPets({ firstName, lastName, occupation, pet }) {
if (occupation === "Teacher" && pet != null) {
console.log(`${firstName} ${lastName}`);
}
}
hogwarts.forEach(belongToGryffindor);
hogwarts.forEach(teachersWithPets);