Skip to content

Mohamad Bader AA#11

Open
noneeeed wants to merge 3 commits intoHackYourAssignment:mainfrom
noneeeed:main
Open

Mohamad Bader AA#11
noneeeed wants to merge 3 commits intoHackYourAssignment:mainfrom
noneeeed:main

Conversation

@noneeeed
Copy link

No description provided.

@github-actions
Copy link

📝 HackYourFuture auto grade

Assignment Score: 0 / 100 ✅

Status: ✅ Passed
Minimum score to pass: 0
🧪 The auto grade is experimental and still being improved

Test Details

@sycons sycons self-assigned this Feb 21, 2026
Copy link

@sycons sycons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of reduce() to calculate the id

}
return book;
});
for (let i = 0; i < markRead.length; i++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done using the other methods! ⭐

@sycons sycons added Reviewed This assignment has been reivewed by a mentor and a feedback has been provided and removed To review labels Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed This assignment has been reivewed by a mentor and a feedback has been provided

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants