Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
155 lines (120 loc) · 4.68 KB
/
Copy pathscript.js
File metadata and controls
155 lines (120 loc) · 4.68 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
let movies = [
{
id: '1',
title: 'Game Night',
year: '2018',
genres: ['Action', 'Comedy', 'Crime'],
releaseDate: '2018-02-28',
actors: ['Rachel McAdams', 'Jesse Plemons', 'Jason Bateman'],
},
{
id: '2',
title: 'Area X: Annihilation',
year: '2018',
genres: ['Adventure', 'Drama', 'Fantasy'],
releaseDate: '2018-02-23',
actors: ['Tessa Thompson', 'Jennifer Jason Leigh', 'Natalie Portman'],
},
{
id: '3',
title: 'Hannah',
year: '2017',
genres: ['Drama'],
releaseDate: '2018-01-24',
actors: ['Charlotte Rampling', 'Andr Wilms', 'Phanie Van Vyve'],
},
];
/*
Go through the variable named movies properly before solvinf the exercises.
Use the variable named movies to solve the requirement below.
*/
// 1. Log the value of the title key in the first movie of the array named `movies`
console.log(movies[0].title);
// 2. Log the value of the title key in the last movie of the array named `movies`
console.log(movies[movies.length -1].title);
// 3. Log the value of the title key in the second movie (index 1) of the array named `movies`
console.log(movies[1].title);
// 4. Log the value of the year key in the first movie of the array named `movies`
console.log(movies[0].year);
// 5. Log all the named of actors (key named actors) of the first movie
console.log(movies[0].actors);
// 6. Log the name of the first actor of the first movie
console.log(movies[0].actors[0]);
// 7. Log the name of the last actor of the first movie
console.log(movies[0].actors[2]);
// 8. Log the name of the second actor (index 1) of the first movie
console.log(movies[0].actors[1]);
// 9. Log the name of the second actor (index 1) of the second movie
console.log(movies[1].actors[1]);
// 10. Log the name of the last actor of the thrid movie
console.log(movies[movies.length - 1].actors[2]);
// 11. Log the name of the second actor (index 1) of the third movie
console.log(movies[movies.length - 1].actors[1]);
// 12. Log all the genres of the third movie
console.log(movies[movies.length - 1].genres);
// 13. Log all the genres of the first movie
console.log(movies[0].genres);
// 14. Log the first genres of the first movie
console.log(movies[0].genres[0]);
// 15. Log the first genres of the second movie
console.log(movies[1].genres[0]);
// 16. Log the last genres of the first movie (using the length property of array)
console.log(movies[0].genres[2]);
// 17. Log the first genres of the second movie (using the length property of array)
console.log(movies[1].genres[0]);
// 18. Log all the genres of the first movie one by one
for(let genre of movies[0].genres) {
console.log(genre)
}
// 19. Log all the genres of the second movie one by one
for(let genre of movies[1].genres) {
console.log(genre)
}
// 20. Log if the first actor of the first movie is `Rachel McAdams` or not (You have to log true or false)
// let result = movies[0].actors[0] == "Rachel McAdams" ? true : false;
// console.log(result);
// 21. Log if the second actor (index 1) of the second movie is `Natalie Portman` or not (You have to log true or false)
// let result = movies[1].actors[1] == "Natalie Portman" ? true : false;
// console.log(result);
// 22. Log if the year of all three movies is greater than `2017` or not one by one. (Log true or false)
for(let movie of movies) {
console.log(movie.year > 2017 ,"is greater");
}
// 23. Log the title of all three movies one by one.
for(let movie of movies) {
console.log(movie.title)
}
// 24. Log if the title of the first movie is `Hannah` or not
let result = movies[0].title == "Hannah" ? true : false;
console.log(result);
// 25. Log the number of actors in all three movies one by one
for(let movie of movies) {
console.log(movie.actors)
}
// 26. Log the number of genres in all three movies one by one
for(let movie of movies) {
console.log(movie.genres.length)
}
// 27. Log the name of all the movies with more than 1 genre
for(let movie of movies) {
if (movie.genres.length > 1) {
console.log(movie.title);
}
}
// 28. Log the name of all the movies with more than 1 actors
for(let movie of movies) {
if (movie.actors.length > 1) {
console.log(movie.title);
}
}
// 29. Log the name of all the movies with exactly 3 actors
for(let movie of movies) {
if (movie.actors.length == 3) {
console.log(movie.title);
}
}
// 30. Log the name of all the movies with year `2018`
for(let movie of movies) {
if (movie.year == 2018)
console.log(movie.title)
}