-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday7.js
More file actions
73 lines (61 loc) · 1.72 KB
/
day7.js
File metadata and controls
73 lines (61 loc) · 1.72 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
// Day 7: Objects
// Activity 1: Object creation and access
// Task 1
const book = {
title: "A Good Girl's guide to Murder",
author: "Holly Jackson",
year: 2019,
details(){
return this.title + this.author ;
},
Updatedyear(yr){
this.year = yr;
}
};
console.log(book);
// Task 2
console.log(`title: ${book.title}`); //output: title: A Good Girl's guide to Murder
console.log(`author: ${book.author}`); //output: author: Holly Jackson
// Activity 2: Object Methods
// Task 3
console.log(book.details()); //output: A Good Girl's guide to Murder Holly Jackson
// Task 4
book.Updatedyear(2016);
console.log(book.year); //output: 2016
// Activity 3: Nested Objects
// Task 5
const library = {
name: "city library",
books: [ {
name: "The palace of illusions",
author: "Chitra Banerjee",
},
{
name: "A good girl's guide to murder",
author: "Holly Jackson",
}
]
}
console.log(library);
// Task 6
console.log(library.name); //utput: city library
console.log(library.books[0].name ," ,", library.books[1].name); //output: The palace of illusions , A good girl's guide to murder
// Activity 4: The this keyword
// Task 7
const book1 = {
name: "abc",
year: 2019,
detail(){
return `title: ${this.name} year: ${this.year}`;
}
}
console.log(book1.detail()); //output: title: abc year: 2019
// Activity 5: Object iteration
// Task 8
for(let i in book1){
console.log(i); //output: name abc year 2019
console.log(book1[i]);
}
// Task 9
console.log(Object.keys(book1)); //output: [name,year]
console.log(Object.values(book1)); //output: [abc,2019]