From a1da126bf37b64dfe893bc1b81908679441003dc Mon Sep 17 00:00:00 2001 From: Zainab Date: Tue, 11 Mar 2025 13:02:18 +0300 Subject: [PATCH] Task completed --- src/challenge.ts | 4 ++++ src/objects.ts | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/challenge.ts b/src/challenge.ts index d697960..03c8e23 100644 --- a/src/challenge.ts +++ b/src/challenge.ts @@ -39,6 +39,10 @@ function addReview( comment: string ): ReviewedBook { // write your code here... + if (!book.reviews) { + book.reviews = []; + } + book.reviews.push({ reviewer, comment }); return book; } diff --git a/src/objects.ts b/src/objects.ts index ef6298f..b7a543d 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -28,7 +28,7 @@ function createBook( ): Book { // write your code here... - return {} as Book; // replace "{} as Book" with what you see is fit + return { title, author, publishedYear, genre }; // replace "{} as Book" with what you see is fit } // DO NOT CHANGE THE LINE OF CODE BELOW (you can use it for testing your code) @@ -51,7 +51,7 @@ const book = createBook( function printBookTitleAndYear(book: Book): string { // write your code here... - return ""; // replace empty string with what you see is fit + return `${book.title} ${book["publishedYear"]}`; // replace empty string with what you see is fit } /** @@ -66,7 +66,7 @@ function printBookTitleAndYear(book: Book): string { */ function addPageCount(book: Book, pageCount: number): Book { // write your code here... - + book.pageCount = pageCount; return book; } @@ -88,7 +88,7 @@ function addPageCount(book: Book, pageCount: number): Book { */ function addISBN(book: Book, ISBN: string): Book { // write your code here... - + book.ISBN = ISBN; return book; } @@ -110,7 +110,7 @@ function addISBN(book: Book, ISBN: string): Book { */ function updatePublishedYear(book: Book, newYear: number): Book { // write your code here... - + book.publishedYear = newYear; return book; } @@ -135,7 +135,11 @@ function updatePublishedYear(book: Book, newYear: number): Book { */ function addSecondAuthor(book: Book, additionalAuthor: string): Book { // write your code here... - + if (typeof book.author === "string") { + book.author = [book.author, additionalAuthor]; + } else { + book.author.push(additionalAuthor); + } return book; }