Conversation
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
sycons
left a comment
There was a problem hiding this comment.
You did a really good job! ⭐
Trying out handling errors based on the type of error and using other functions and seeing how they work.
- Setup & Configuration ✅
- Data Structure ✅
- Required Functions ✅
- Error Handling ✅
- Display (Chalk) ✅
| const books = fs.readFileSync('books.json', 'utf8'); | ||
| return JSON.parse(books); | ||
| } catch (error) { | ||
| if (error.code === 'ENOENT') { |
There was a problem hiding this comment.
Good use of catching different error types and handling it accordingly ⭐
|
|
||
| function addBook(book) { | ||
| // TODO: Implement this function | ||
| const maxId = books.reduce((max, b) => (b.id > max ? b.id : max), 0); |
There was a problem hiding this comment.
Nice use of reduce() to calculate the id ⭐
| } | ||
| return book; | ||
| }); | ||
| for (let i = 0; i < markRead.length; i++) { |
There was a problem hiding this comment.
This for loop can be removed. map() returns a new array. This can be passed to saveBooks().
More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
| @@ -1,53 +1,106 @@ | |||
| // Place here the file operation functions for loading and saving books | |||
| import fs from 'node:fs'; | |||
There was a problem hiding this comment.
This import will also work with just import fs from 'fs'; It's not necessary to specify node:
| console.log(getUnreadBooks()); | ||
| console.log(chalk.bold('\nBooks by genre (fiction):')); | ||
| console.log(getBooksByGenre('fiction')); | ||
| const newBook = addBook({ |
No description provided.