Day 8 — Objects — literals and access

Homework

Problem 1 Part 1
const book = {
    title : "abc",
    author : "xyz",
    year : 2002,
    pages : 1000,

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 2 Part 2
summary() {
        return `${this.title} by ${this.author} (${this.year})`
    }
}

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 3 Part 3
console.log(book["title"])
console.log(book.summary())

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 4 Part 4
Object.entries(book).forEach(([key,value]) => {
   console.log(`${key} : ${value}`) 
});

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 5 Part 5
console.log("------------------------------------------------------")
const obj = {...book};
obj.title = 'kal';

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 6 Part 6
Object.entries(obj).forEach(([key,value]) => {
    console.log(`${key} : ${value}`) 
});

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 7 Part 7
console.log("------------------------------------------------------")

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 8 Part 8
Object.entries(book).forEach(([key,value]) => {
   console.log(`${key} : ${value}`) 
});

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).