From c3c7772bf205d64683dfdb69227ed7d74249044a Mon Sep 17 00:00:00 2001 From: EbrahimAlenezi Date: Mon, 21 Jul 2025 18:53:41 +0100 Subject: [PATCH] finished task-ts-objects --- src/objects.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/objects.ts b/src/objects.ts index ef6298f..6120fbe 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -26,9 +26,14 @@ function createBook( publishedYear: number, genre: string ): Book { - // write your code here... + const book: Book = { + title: title, + author: author, + publishedYear: publishedYear, + genre: genre, + }; - return {} as Book; // replace "{} as Book" with what you see is fit + return book; // return the created book object } // DO NOT CHANGE THE LINE OF CODE BELOW (you can use it for testing your code) @@ -51,7 +56,8 @@ 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"]; // return title and published year separated by a space } /** @@ -65,7 +71,7 @@ function printBookTitleAndYear(book: Book): string { * // => { title: "Hitchhiker's Guide to The Galaxy", author: "Douglas Adams", publishedYear: 1965, genre: "Sci-Fi", pageCount: 320 } */ function addPageCount(book: Book, pageCount: number): Book { - // write your code here... + book.pageCount = pageCount; return book; } @@ -87,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; } @@ -109,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; } @@ -134,8 +140,6 @@ function updatePublishedYear(book: Book, newYear: number): Book { * // } */ function addSecondAuthor(book: Book, additionalAuthor: string): Book { - // write your code here... - return book; }