Repository navigation
Expand file tree
/
Copy pathobject.js
More file actions
315 lines (239 loc) · 7.03 KB
/
Copy pathobject.js
File metadata and controls
315 lines (239 loc) · 7.03 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// const book = {
// title: "The Last Kingdom",
// author: "Bernard Cornwell",
// genres: ["historical prose", "adventure"],
// rating: 8.38,
// };
// for (const key in book) {
// // Ключ
// console.log(key);
// // Значення властивості з таким ключем
// console.log(book[key]);
// }
// const array = [1, 2, 3, 4, 5];
// console.log(typeof (array));
// const book = {
// title: "The Last Kingdom",
// author: "Bernard Cornwell",
// genres: ["historical prose", "adventure"],
// isPublic: true,
// rating: 8.38,
// };
// const bookTitle = book.title;
// alert(bookTitle); // 'The Last Kingdom'
// const bookGenres = book.genres;
// alert(bookGenres); // ['historical prose', 'adventurs']
// const bookPrice = book.price;
// alert(bookPrice); // undefined
// function sum (numbers) {
// "use strict";
// let total;
// for(let i = 0; i < numbers.length; i += 1){
// total += numbers[i];
// }
// return total;
// };
// const user = {
// name: "Jacques Gluke",
// tag: "jgluke",
// location: {
// country: "Jamaica",
// city: "Ocho Rios",
// },
// hobbies: ["swiming", "music", "sci-fi"],
// };
// const location = user.location;
// console.log(location); // Об'єкт location
// const country = user.location.country;
// console.log(country); // 'Jamaica'
// const propName = "name";
// const user = {
// age: 25,
// // Ім'я цієї властивості буде взяте зі значення змінної propName
// name: "Генрі Сибола",
// };
// console.log(user.name); // 'Генрі Сибола'
// const book = {
// title: "The Last Kingdom",
// author: "Bernard Cornwell",
// genres: ["historical prose", "adventure"],
// rating: 8.38,
// };
// const keys = Object.keys(book);
// alert(keys)
// console.log(keys)
// const values = Object.values(book);
// alert(values);
// console.log(values);
// const keys = Object.keys(book);
// console.log(keys); // ['title', 'author', 'genres', 'rating']
// const x = {};
// const fn = function (myObject) {
// console.log(myObject)
// };
// fn({ a: 1, b: 2, });
// const playlist = {
// name: "My favorite playlist",
// rating: 9.5,
// tracks: ['Everyday', 'Fashion killa', 'Sundress'],
// trackCount: 3,
// };
// console.log(playlist);
// const propertyName = 'tracks';
// // console.log(playlist.rating)
// // console.log(playlist['rating'])
// console.log(playlist.propertyName);
// console.log(playlist[propertyName]);
// const username = 'Mango';
// const email = 'mango@mail.com';
// const color = 'black';
// const signupData = {
// username,
// email,
// color,
// }
// console.log(signupData)
/* МЕТОДИ ОБʼЄКТА */
// const playlist = {
// name: "My favorite playlist",
// rating: 9.5,
// tracks: ['Everyday', 'Fashion killa', 'Sundress'],
// changeName(newName) {
// console.log('this inside changeName: ', this);
// this.name = newName;
// },
// addTrack(track) {
// this.tracks.push(track);
// },
// updateRating(newRating) {
// this.rating = newRating;
// },
// getTrackCount() {
// return this.tracks.length;
// }
// };
// console.log(playlist.getTrackCount())
// playlist.changeName('Valera');
// console.log(playlist);
// playlist.addTrack('XO life');
// console.log(playlist)
// playlist.updateRating(6);
// console.log(playlist)
/* Перебір масива */
// const feedback = {
// good: 5,
// neutral: 10,
// bad: 3,
// };
// let totalFeedback = 0;
// const keys = Object.keys(feedback);
// console.log(keys)
// for (const key of keys) {
// console.log(feedback[key])
// totalFeedback += feedback[key]
// }
// console.log(totalFeedback)
// const values = Object.values(feedback)
// console.log(values)
// for (const value of values) {
// console.log(value)
// }
// const friends = [
// { name: 'Mango', online: false, },
// { name: 'Kiwi', online: true, },
// { name: 'Poly', online: true, },
// { name: 'Ajax', online: false, }
// ]
// // console.table(friends)
// const findFriendByName = function (allFriends, friendName) {
// for (const friend of friends) {
// // console.log(friend)
// console.log(friend.name);
// if (friend.name === friendName) {
// return 'YESSSIR';
// }
// }
// return 'Nei';
// }
// console.log(findFriendByName(friends, 'Poly'))
// console.log(findFriendByName(friends, 'Chelsy'))
// const getAllNames = function (allFriends) {
// const names = []
// for (const friend of allFriends) {
// console.log(friend.name);
// names.push(friend.name);
// }
// return names;
// }
// console.log(getAllNames(friends))
// const getOnlineFriends = function (allFriends) {
// const onlineFriends = [];
// for (const friend of allFriends) {
// console.log(friend);
// console.log(friend.online);
// if (friend.online) {
// onlineFriends.push(friend)
// }
// }
// return onlineFriends;
// }
// console.log(getOnlineFriends(friends));
// const getOfflineFriends = function (allFriends) {
// const offlineFriends = [];
// for (const friend of allFriends) {
// console.log(friend);
// console.log(friend.online);
// if (!friend.online) {
// offlineFriends.push(friend)
// }
// }
// return offlineFriends;
// }
// console.log(getOfflineFriends(friends));
// const cart = {
// items: [],
// }
// const colors = [
// { hex: "#f44336", rgb: "244,67,54" },
// { hex: "#2196f3", rgb: "33,150,243" },
// { hex: "#4caf50", rgb: "76,175,80" },
// { hex: "#ffeb3b", rgb: "255,235,59" },
// ];
// const hexColors = [];
// const rgbColors = [];
// // Change code below this line
// for (const color of colors) {
// hexColors.push(color.hex)
// rgbColors.push(color.rgb)
// console.log(color.hex)
// }
// const forecast = {
// today: {
// low: 28,
// high: 32,
// icon: "https://www.flaticon.com/svg/static/icons/svg/861/861059.svg",
// },
// tomorrow: {
// low: 27,
// high: 31,
// },
// };
// // Change code below this line
// const { today: {highToday, lowToday, },
// tomorrow: {highTomorrow, lowTomorrow},
// icon: { tomorrowIcon = "https://www.flaticon.com/svg/static/icons/svg/2204/2204346.svg",
// todayIcon = "https://www.flaticon.com/svg/static/icons/svg/861/861059.svg" }, } = highTemperatures;
// const forecast = {
// today: {
// low: 28,
// high: 32,
// icon: "https://www.flaticon.com/svg/static/icons/svg/861/861059.svg",
// },
// tomorrow: {
// low: 27,
// high: 31,
// },
// };
// // Change code below this line
// const { today: { low: lowToday, high: highToday, icon: todayIcon = "https://www.flaticon.com/svg/static/icons/svg/861/861059.svg",
// icon: tomorrrowIcon = "https://www.flaticon.com/svg/static/icons/svg/2204/2204346.svg",}, tomorrow: { low: lowTomorrow, high: highTomorrow}, } = highTemperatures;