-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday7.js
More file actions
58 lines (47 loc) · 1.1 KB
/
day7.js
File metadata and controls
58 lines (47 loc) · 1.1 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
// Task 1
let book = {
title: "Wings of Fire",
author: "Dr. APJ Abdul Kalam",
year: 1925
};
console.log(book);
// Task 2
console.log(book.title);
console.log(book.author);
// Task 3
book.getDetails = function() {
return `${this.title} is written by ${this.author}.`;
};
console.log(book.getDetails());
// Task 4
book.newYear = function(newYear) {
this.year = newYear;
};
book.newYear(2024);
console.log(book);
// Task 5
let library = {
name: "Collge Library",
books: [
{ title: "Wings of Fire", author: "Dr. APJ Abdul Kalam", year: 1995 },
{ title: "My experiments with truth", author: "Mahatma Gandhi", year: 1942 }
]
};
console.log(library);
// Task 6
console.log(library.name);
library.books.forEach(book => console.log(book.title));
// Task 7
book.getTitleYear = function() {
return `${this.title}, published in ${this.year}`;
};
console.log(book.getTitleYear());
// Task 8
for (let key in book) {
if (book.hasOwnProperty(key)) {
console.log(`${key}: ${book[key]}`);
}
}
// Task 9
console.log(Object.keys(book));
console.log(Object.values(book));