From 60ba76d6f9fd288bab0905ebae123e52b47d12fd Mon Sep 17 00:00:00 2001 From: Bashaier AlMeshaileh <56195895+bkmushaileh@users.noreply.github.com> Date: Mon, 21 Jul 2025 20:43:06 +0300 Subject: [PATCH] Done without the challange --- src/objects.ts | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/objects.ts b/src/objects.ts index ef6298f..50fa9b8 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -26,9 +26,13 @@ function createBook( publishedYear: number, genre: string ): Book { - // write your code here... - - return {} as Book; // replace "{} as Book" with what you see is fit + const myBook = { + title: title, + author: author, + publishedYear: publishedYear, + genre: genre, + }; + return myBook; // 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) @@ -38,6 +42,7 @@ const book = createBook( 1965, "Sci-Fi" ); +console.log(book); /** * `printBookTitleAndYear` function: @@ -51,9 +56,9 @@ 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 } - +console.log(printBookTitleAndYear(book)); /** * `addPageCount` function: * - Accepts: @@ -66,10 +71,10 @@ function printBookTitleAndYear(book: Book): string { */ function addPageCount(book: Book, pageCount: number): Book { // write your code here... - + book.pageCount = pageCount; return book; } - +console.log(addPageCount(book, 300)); /** * `addISBN` function: * - Accepts: @@ -88,10 +93,10 @@ function addPageCount(book: Book, pageCount: number): Book { */ function addISBN(book: Book, ISBN: string): Book { // write your code here... - + book.ISBN = ISBN; return book; } - +console.log(addISBN(book, "978-3-16-148410-0")); /** * `updatePublishedYear` function: * - Accepts: @@ -110,10 +115,10 @@ function addISBN(book: Book, ISBN: string): Book { */ function updatePublishedYear(book: Book, newYear: number): Book { // write your code here... - + book.publishedYear = newYear; return book; } - +console.log(updatePublishedYear(book, 2022)); /** * `addSecondAuthor` function: * - Accepts: @@ -135,9 +140,16 @@ function updatePublishedYear(book: Book, newYear: number): Book { */ function addSecondAuthor(book: Book, additionalAuthor: string): Book { // write your code here... - + //to know if it is array or string + if (Array.isArray(book.author) === true) { + book.author.push(additionalAuthor); + } else { + book.author = [book.author, additionalAuthor]; + } return book; } +console.log(addSecondAuthor(book, "bashier")); +console.log(addSecondAuthor(book, "Khaled")); export { createBook,