diff --git a/src/challenge.ts b/src/challenge.ts index d697960..ac57497 100644 --- a/src/challenge.ts +++ b/src/challenge.ts @@ -33,12 +33,18 @@ interface ReviewedBook extends Book { * // reviews: [{ reviewer: "Alice", comment: "A thought-provoking novel!" }] * // } */ + + function addReview( book: ReviewedBook, reviewer: string, comment: string ): ReviewedBook { - // write your code here... + // write your code here... + if(book.reviews == undefined) + book.reviews = [{reviewer, comment}] + else + book.reviews?.push ({reviewer, comment}) return book; } diff --git a/src/objects.ts b/src/objects.ts index ef6298f..6905b89 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -28,7 +28,12 @@ function createBook( ): Book { // write your code here... - return {} as Book; // replace "{} as Book" with what you see is fit + return { + title: title, + author: author, + publishedYear: publishedYear, + genre: genre + } 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) @@ -50,8 +55,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"]}` } /** @@ -66,7 +70,7 @@ function printBookTitleAndYear(book: Book): string { */ function addPageCount(book: Book, pageCount: number): Book { // write your code here... - + book.pageCount = pageCount return book; } @@ -88,7 +92,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 +114,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 +139,9 @@ function updatePublishedYear(book: Book, newYear: number): Book { */ function addSecondAuthor(book: Book, additionalAuthor: string): Book { // write your code here... - + let authors = [book.author as string] + authors.push(additionalAuthor) + book.author = authors; return book; }