Skip to content
Open

done #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ function addReview(
reviewer: string,
comment: string
): ReviewedBook {
// write your code here...
const newReview: Review = { reviewer, comment };
if (!book.reviews) {
book.reviews = [];
}
book.reviews.push(newReview);

return book;
}
Expand Down
28 changes: 15 additions & 13 deletions src/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ function createBook(
publishedYear: number,
genre: string
): Book {
// write your code here...

return {} as Book; // replace "{} as Book" with what you see is fit
return {
title,
author,
publishedYear,
genre,
};
}

// DO NOT CHANGE THE LINE OF CODE BELOW (you can use it for testing your code)
Expand All @@ -49,9 +52,7 @@ const book = createBook(
* // => "Hitchhiker's Guide to The Galaxy 1965"
*/
function printBookTitleAndYear(book: Book): string {
// write your code here...

return ""; // replace empty string with what you see is fit
return book.title + " " + book["publishedYear"];
}

/**
Expand All @@ -65,8 +66,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;
}

Expand All @@ -87,8 +87,7 @@ function addPageCount(book: Book, pageCount: number): Book {
* // }
*/
function addISBN(book: Book, ISBN: string): Book {
// write your code here...

book.ISBN = ISBN;
return book;
}

Expand All @@ -109,7 +108,7 @@ function addISBN(book: Book, ISBN: string): Book {
* // }
*/
function updatePublishedYear(book: Book, newYear: number): Book {
// write your code here...
book.publishedYear = newYear;

return book;
}
Expand All @@ -134,8 +133,11 @@ function updatePublishedYear(book: Book, newYear: number): Book {
* // }
*/
function addSecondAuthor(book: Book, additionalAuthor: string): Book {
// write your code here...

if (typeof book.author === "string") {
book.author = [book.author, additionalAuthor];
} else {
book.author.push(additionalAuthor);
}
return book;
}

Expand Down