From 69623637f8e8d2094346c7cd5138324bf117d084 Mon Sep 17 00:00:00 2001 From: Dana Aldulijan Date: Tue, 11 Mar 2025 13:28:22 +0300 Subject: [PATCH] done part 1 --- src/challenge.ts | 8 +++++++- src/objects.ts | 21 +++++++++++++++------ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/challenge.ts b/src/challenge.ts index d697960..748caec 100644 --- a/src/challenge.ts +++ b/src/challenge.ts @@ -39,7 +39,13 @@ function addReview( comment: string ): ReviewedBook { // write your code here... - + const reviewedBook: Review = { + reviewer: reviewer, + comment: comment, + }; + Array.isArray(book.reviews) + ? book.reviews.push(reviewedBook) + : (book.reviews = [reviewedBook]); return book; } diff --git a/src/objects.ts b/src/objects.ts index ef6298f..81e1a55 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -27,8 +27,13 @@ function createBook( genre: string ): Book { // write your code here... - - return {} as Book; // replace "{} as Book" with what you see is fit + const NewBook: Book = { + title: title, + author: author, + publishedYear: publishedYear, + genre: genre, + }; + return NewBook as Book; // 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 +56,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 +71,7 @@ function printBookTitleAndYear(book: Book): string { */ function addPageCount(book: Book, pageCount: number): Book { // write your code here... - + book.pageCount = pageCount; return book; } @@ -88,7 +93,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 +115,7 @@ function addISBN(book: Book, ISBN: string): Book { */ function updatePublishedYear(book: Book, newYear: number): Book { // write your code here... - + book.publishedYear = newYear; return book; } @@ -136,6 +141,10 @@ function updatePublishedYear(book: Book, newYear: number): Book { function addSecondAuthor(book: Book, additionalAuthor: string): Book { // write your code here... + Array.isArray(book.author) + ? book.author.push(additionalAuthor) + : (book.author = [book.author, additionalAuthor]); + return book; }