Conversation
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
mo92othman
left a comment
There was a problem hiding this comment.
Hi @jivvyjams
Overall, good work 👍
Please make sure to include the required project setup files (like package.json and .prettierrc) and test running the app yourself before submitting. These are part of the assignment requirements.
Good luck in the next modules!
| function printAllBooks() { | ||
| // TODO: Implement this function | ||
| // Loop through and display with chalk | ||
| // Use green for read books, yellow for unread | ||
| // Use cyan for titles | ||
| const books = loadBooks(); | ||
|
|
||
| console.log("\nAll Books:"); | ||
| books.forEach((b) => { | ||
| const color = b.read ? chalk.green : chalk.yellow; | ||
| const status = b.read ? "✓ Read" : "⚠ Unread"; | ||
|
|
||
| console.log( | ||
| color(`${b.id}. `) + | ||
| chalk.cyan(b.title) + | ||
| color(` by ${b.author} (${b.genre}) ${status}`), | ||
| ); | ||
| }); |
There was a problem hiding this comment.
printAllBooks is defined again here. It was already defined earlier. Please keep only one version to avoid confusion and bugs.
| function printSummary() { | ||
| // TODO: Implement this function | ||
| // Show statistics with chalk | ||
| // Display total books, read count, unread count | ||
| // Use bold for stats | ||
| } No newline at end of file | ||
| const books = loadBooks(); | ||
| const total = books.length; | ||
| const readCount = books.filter((b) => b.read === true).length; | ||
| const unreadCount = total - readCount; | ||
|
|
||
| console.log(chalk.bold("\n📊 SUMMARY 📊")); | ||
| console.log(chalk.bold(`Total Books: ${total}`)); | ||
| console.log(chalk.bold(`Read: ${readCount}`)); | ||
| console.log(chalk.bold(`Unread: ${unreadCount}`)); | ||
| } |
There was a problem hiding this comment.
Same for this, printSummary is also defined twice. Duplicate functions make the file harder to maintain.
| module.exports = { | ||
| loadBooks, | ||
| saveBooks, | ||
| addBook, | ||
| getUnreadBooks, | ||
| getBooksByGenre, | ||
| markAsRead, | ||
| getTotalBooks, | ||
| hasUnreadBooks, | ||
| printAllBooks, | ||
| printSummary, | ||
| }; |
There was a problem hiding this comment.
module.exports appears two times. Here, and previously in line 115 Keep one export block at the end of the file.
| books.forEach((book) => { | ||
| if (typeof book.id === "number" && book.id > maxId) maxId = book.id; | ||
| }); | ||
| const newBook = { | ||
| id: maxId + 1, |
There was a problem hiding this comment.
Nice job generating the ID dynamically!
| if (command === "add") { | ||
| const title = process.argv[3]; | ||
| const author = process.argv[4]; | ||
| const genre = process.argv[5]; | ||
| addBook({ | ||
| title: "Nudge", | ||
| author: "Richard Thaler", | ||
| genre: "Pyschology", | ||
| }); | ||
| } |
There was a problem hiding this comment.
You read title, author, genre from CLI args, but you do not use them. Right now addBook always adds hardcoded "Nudge" values.
| @@ -1,13 +1,42 @@ | |||
| // This is the entrypoint for your application. | |||
| // node app.js | |||
| const chalk = require("chalk"); | |||
There was a problem hiding this comment.
chalk is imported but never used in this file.
No description provided.