diff --git a/src/objects.ts b/src/objects.ts index ef6298f..83e95f6 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -1,3 +1,5 @@ +import { ad } from "@faker-js/faker/dist/airline-BcEu2nRk"; + // don't change this interface interface Book { title: string; @@ -28,7 +30,13 @@ function createBook( ): Book { // write your code here... - return {} as Book; // replace "{} as Book" with what you see is fit + const carbook: Book = { + title: title, + author: author, + publishedYear: publishedYear, + genre: genre, + }; + return carbook; } // DO NOT CHANGE THE LINE OF CODE BELOW (you can use it for testing your code) @@ -50,8 +58,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"]; } /** @@ -65,6 +72,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 { + book.pageCount = pageCount; // write your code here... return book; @@ -88,10 +96,16 @@ function addPageCount(book: Book, pageCount: number): Book { */ function addISBN(book: Book, ISBN: string): Book { // write your code here... + + book.ISBN = ISBN; + + + + return book; } - +// addISBN(book, "978-3-16-148410-0"); /** * `updatePublishedYear` function: * - Accepts: @@ -110,10 +124,12 @@ function addISBN(book: Book, ISBN: string): Book { */ function updatePublishedYear(book: Book, newYear: number): Book { // write your code here... - + + book.publishedYear = newYear; return book; } +// updatePublishedYear(book, 2022); /** * `addSecondAuthor` function: * - Accepts: @@ -135,10 +151,22 @@ function updatePublishedYear(book: Book, newYear: number): Book { */ function addSecondAuthor(book: Book, additionalAuthor: string): Book { // write your code here... + if (Array.isArray(book.author)) { + book.author.push(additionalAuthor); + } else { + book.author = [book.author, additionalAuthor]; + } + + + + + return book; } + + export { createBook, printBookTitleAndYear,