Skip to content
Open
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
7 changes: 7 additions & 0 deletions src/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ function addReview(
comment: string
): ReviewedBook {
// write your code here...
const newReview = {
reviewer: reviewer,
comment: comment,
};
if (newReview !== null) {
book.reviews?.push(newReview);
}

return book;
}
Expand Down
22 changes: 19 additions & 3 deletions src/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ function createBook(
genre: string
): Book {
// write your code here...
const newBook: Book = {
title: title,
author: author,
publishedYear: publishedYear,
genre: genre,
};

return {} as Book; // replace "{} as Book" with what you see is fit
return { title, author, publishedYear, 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)
Expand All @@ -51,7 +57,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"]; // replace empty string with what you see is fit
}

/**
Expand All @@ -66,6 +72,7 @@ function printBookTitleAndYear(book: Book): string {
*/
function addPageCount(book: Book, pageCount: number): Book {
// write your code here...
book.pageCount = pageCount;

return book;
}
Expand All @@ -88,6 +95,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 @@ -110,7 +118,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 @@ -136,6 +144,14 @@ function updatePublishedYear(book: Book, newYear: number): Book {
function addSecondAuthor(book: Book, additionalAuthor: string): Book {
// write your code here...

if (Array.isArray(book.author)) {
// clause gaurd
book.author.push(additionalAuthor);
} else {
const author = book.author;
book.author = [author, additionalAuthor];
}

return book;
}

Expand Down
Loading