From 624a5e2ea5a6180dc9bf08cbc789922e15a815d9 Mon Sep 17 00:00:00 2001 From: Jose Chabel Date: Tue, 26 May 2026 05:30:31 +0200 Subject: [PATCH] done --- src/books.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 7 deletions(-) diff --git a/src/books.js b/src/books.js index c8119bb..4058aa0 100644 --- a/src/books.js +++ b/src/books.js @@ -38,27 +38,96 @@ // Your code here: -const booksArray = []; - +const booksArray = [ + { + title: "The Old Man and the Sea", + pages: 128, + author: "Ernest Hemingway", + details: { + language: "English", + description: "One of Hemingway's most famous works, it tells the story of Santiago...", + } + }, + { + title: "The Airbnb Story", + pages: 256, + author: "Leight Gallagher", + details: { + language: "English", + description: "This is the remarkable behind-the-scenes story of the creation and growth of Airbnb...", + } + }, + { + title: "Educated - A Memoir", + pages: 352, + author: "Tara Westover", + details: { + language: "English", + description: "Educated is an account of the struggle for self-invention...", + } + }, + { + title: "The Art of Learning", + pages: 288, + author: "Josh Waitzkin", + details: { + language: "English", + description: "The Art of Learning takes readers through Waitzkin's unique journey to excellence. He explains in clear detail how a well-thought-out, principled approach to learning is what separates success from failure.", + } + } +]; +// display the books array in the console +console.log(booksArray); // Iteration 2 | Book Details -function getBookDetails() { +function getBookDetails(book) { // Your code here: - + if ( + typeof book === "object" || book === null || + typeof book.title !== "string" || + typeof book.author !== "string" || + typeof book.pages !== "number" || + typeof book.details !== "object" || book.details === null + ) + { + console.error("Invalid book object"); + return null; + } + + return { + TITLE: book.title, + AUTHOR: book.author, + PAGES: book.pages + }; } - - +booksArray.forEach(book => { + console.log(getBookDetails(book)); +}); // Iteration 3 | Delete Language // Your code here: - +booksArray.forEach(book => { + if (book.details && typeof book.details === "object") { + delete book.details.language; + } +}); +console.log(booksArray); // Iteration 4 | Estimated Reading Time // Your code here: +booksArray.forEach(book => { + if (typeof book.pages === "number" && book.pages > 0) { + const readingMinutes = Math.ceil((book.pages * 500) / 90); + book.readingTime = readingMinutes; + } else { + book.readingTime = 0; + } +}); +console.log(booksArray);