From 7ba04feafa319f55889543de73837f514a870385 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 11:26:25 +0100 Subject: [PATCH 01/15] setup and configured --- .gitignore | 4 ++++ .prettierrc | 7 +++++++ package.json | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 .prettierrc create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 2b76d7c..cb04f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,7 @@ dist vite.config.js.timestamp-* vite.config.ts.timestamp-* +node_modules/ +package-lock.json +.env +.DS_store diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b2b47dc --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": true, + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "es5", + "printWidth": 80 +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..32db0e6 --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "c55-core-week-6", + "version": "1.0.0", + "description": "The week 6 assignment for the HackYourFuture Core program can be found at the following link: https://hub.hackyourfuture.nl/core-program-week-6-assignment", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/hannahwn/c55-core-week-6.git" + }, + "keywords": [], + "author": "", + "license": "ISC", + "type": "commonjs", + "bugs": { + "url": "https://github.com/hannahwn/c55-core-week-6/issues" + }, + "homepage": "https://github.com/hannahwn/c55-core-week-6#readme", + "dependencies": { + "chalk": "^4.1.2" + } +} From 64a56f3c9a1aa14850a107f78575773aa3132b8d Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 12:10:03 +0100 Subject: [PATCH 02/15] made a list of books --- reading-list-manager/books.json | 63 ++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/reading-list-manager/books.json b/reading-list-manager/books.json index 0637a08..3c550b2 100644 --- a/reading-list-manager/books.json +++ b/reading-list-manager/books.json @@ -1 +1,62 @@ -[] \ No newline at end of file +const books = [ + + { + id: 1, + title: "1984", + author: "George Orwell", + genre: "Fiction", + read: false + }, + + { + id: 2, + title: "The Havoc of Choice", + author: "Wanjiru Koinange", + genre: "African Literature", + read: true + }, + + { + id: 3, + title: "CreepShow", + author: "Stephen King", + genre: "Comic", + read: false + }, + + { + id: 4, + title: "Fire and Ice", + author: "Erin Hunter", + genre: "Fiction", + read: true + }, + + { + id: 5, + title: "Toxic Bachelors", + author: "Daniella Steel", + genre: "Adult", + read: false + }, + + { + id: 6, + title: "Foxes in a fix", + author: "Bruce Cameron", + genre: "Animals", + read: true + }, + + { + id: 7, + title: "The Luzhin Defense", + author: "Vladimir Nabokov", + genre: "Chess", + read: false + } + + // ... at least 5 books +]; + +module.exports = { books }; \ No newline at end of file From da0a961bf3caed2e00e3928b090b1c56699bec6c Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 12:21:50 +0100 Subject: [PATCH 03/15] corrected error in my array --- reading-list-manager/books.json | 77 ++++++++++++++++----------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/reading-list-manager/books.json b/reading-list-manager/books.json index 3c550b2..d0850c3 100644 --- a/reading-list-manager/books.json +++ b/reading-list-manager/books.json @@ -1,62 +1,61 @@ -const books = [ +[ { - id: 1, - title: "1984", - author: "George Orwell", - genre: "Fiction", - read: false + "id": 1, + "title": "1984", + "author": "George Orwell", + "genre": "Fiction", + "read": false }, { - id: 2, - title: "The Havoc of Choice", - author: "Wanjiru Koinange", - genre: "African Literature", - read: true + "id": 2, + "title": "The Havoc of Choice", + "author": "Wanjiru Koinange", + "genre": "African Literature", + "read": true }, { - id: 3, - title: "CreepShow", - author: "Stephen King", - genre: "Comic", - read: false + "id": 3, + "title": "CreepShow", + "author": "Stephen King", + "genre": "Comic", + "read": false }, { - id: 4, - title: "Fire and Ice", - author: "Erin Hunter", - genre: "Fiction", - read: true + "id": 4, + "title": "Fire and Ice", + "author": "Erin Hunter", + "genre": "Fiction", + "read": true }, { - id: 5, - title: "Toxic Bachelors", - author: "Daniella Steel", - genre: "Adult", - read: false + "id": 5, + "title": "Toxic Bachelors", + "author": "Daniella Steel", + "genre": "Adult", + "read": false }, { - id: 6, - title: "Foxes in a fix", - author: "Bruce Cameron", - genre: "Animals", - read: true + "id": 6, + "title": "Foxes in a fix", + "author": "Bruce Cameron", + "genre": "Animals", + "read": true }, { - id: 7, - title: "The Luzhin Defense", - author: "Vladimir Nabokov", - genre: "Chess", - read: false + "id": 7, + "title": "The Luzhin Defense", + "author": "Vladimir Nabokov", + "genre": "Chess", + "read": false } - // ... at least 5 books -]; + +] -module.exports = { books }; \ No newline at end of file From a685ad7a7f3ea9e7a2edaeec7c2a4dd96e71d39e Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 12:47:13 +0100 Subject: [PATCH 04/15] added loadBooks() --- reading-list-manager/readingList.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index 84febab..f83ce1a 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -1,11 +1,29 @@ // Place here the file operation functions for loading and saving books +const fs = require('fs'); +const chalk = require('chalk'); + +const FILE_NAME = 'books.json'; function loadBooks() { // TODO: Implement this function - // Read from books.json + // Read from books.json + try{ + const data = fs.readdirSync(FILE_NAME,'utf8'); + return JSON.parse(data); + } // Handle missing file (create empty array) - // Handle invalid JSON (notify user, use empty array) - // Use try-catch for error handling + catch (error){ + if (error.code === 'ENOENT'){ + console.log(chalk.yellow('No books file found.Starting again')); + return[]; + } + // Handle invalid JSON (notify user, use empty array) + if (error instanceof SyntaxError){ + console.log(chalk.red('Error loading books:'), error.message); + return[]; + } + } + //Use try-catch for error handling } function saveBooks(books) { From 561ac1cf3e050292d033f5ea1e53330ffbcec31c Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 18:46:52 +0100 Subject: [PATCH 05/15] added saveBooks --- reading-list-manager/readingList.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index f83ce1a..9b2521f 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -19,17 +19,28 @@ function loadBooks() { } // Handle invalid JSON (notify user, use empty array) if (error instanceof SyntaxError){ - console.log(chalk.red('Error loading books:'), error.message); + console.log(chalk.red('Book file is broken. Starting fresh!')); return[]; } + //Use try-catch for error handling + console.log(chalk.red('Error loading books:'),error.message); + return[]; } - //Use try-catch for error handling + } function saveBooks(books) { // TODO: Implement this function // Write books array to books.json // Use try-catch for error handling + try{ + const data =JSON.stringify(books,null,2); + fs.writeFileSync(FILE_NAME,data); + console.log(chalk.green('Saved :')); + } + catch (error){ + console.log(chalk.red('Save failed'),error.message); + } } function addBook(book) { From fcc16ea0f5d85963bf92d2d9ed5d5c4f20eda688 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 19:20:32 +0100 Subject: [PATCH 06/15] added addBook --- reading-list-manager/readingList.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index 9b2521f..d0b0a28 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -43,8 +43,29 @@ function saveBooks(books) { } } -function addBook(book) { +function addBook(books, titles, author, genre) { // TODO: Implement this function + //Create new book + const newBook = { + id: books.length + 1, + title: title, + author: author, + genre: genre, + read: false + }; + + + books.push(newBook); + + + saveBooks(books); + + + console.log(chalk.green(`✓ Added "${title}"`)); + + return books; + + } function getUnreadBooks() { From 5c966d603df6c81aa0e2d27936a65cb3ed7bb5e9 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 19:24:34 +0100 Subject: [PATCH 07/15] added getBooksByGenre --- reading-list-manager/readingList.js | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index d0b0a28..00e16d0 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -68,12 +68,45 @@ function addBook(books, titles, author, genre) { } -function getUnreadBooks() { +function getUnreadBooks(books) { // TODO: Implement this function using filter() + const unreadBooks = books.filter(function(book) { + return book.read === false; + }); + + console.log(chalk.blue('\n--- UNREAD BOOKS ---')); + if (unreadBooks.length === 0) { + console.log(chalk.yellow('No unread books!')); + } else { + for (let i = 0; i < unreadBooks.length; i++) { + const book = unreadBooks[i]; + console.log(`${book.id}. ${book.title} by ${book.author}`); + } + } + + return unreadBooks; + + } -function getBooksByGenre(genre) { +function getBooksByGenre(books, genre) { // TODO: Implement this function using filter() + const genreBooks = books.filter(function(book) { + return book.genre.toLowerCase() === genre.toLowerCase(); + }); + + console.log(chalk.blue(`\n--- ${genre} BOOKS ---`)); + if (genreBooks.length === 0) { + console.log(chalk.yellow(`No ${genre} books!`)); + } else { + for (let i = 0; i < genreBooks.length; i++) { + const book = genreBooks[i]; + const readStatus = book.read ? '✓' : '○'; + console.log(`${readStatus} ${book.id}. ${book.title} by ${book.author}`); + } + } + + return genreBooks; } function markAsRead(id) { From 66392ed6926468cc4f789a285d09fc0efd647c02 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 19:36:34 +0100 Subject: [PATCH 08/15] Added to get total books --- reading-list-manager/readingList.js | 39 ++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index 00e16d0..8ccdc3a 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -109,12 +109,49 @@ function getBooksByGenre(books, genre) { return genreBooks; } -function markAsRead(id) { +function markAsRead(books, id) { // TODO: Implement this function using map() + const updatedBooks = books.map(function(book) { + + if (book.id === id) { + return { + id: book.id, + title: book.title, + author: book.author, + genre: book.genre, + read: true + }; + } + + return book; + }); + + //Does book exist? + + const oldBook = books.find(function(book) { + return book.id === id; + }); + + if (!oldBook) { + console.log(chalk.red(`✗ Book #${id} not found!`)); + return books; + } + + // Save changes + saveBooks(updatedBooks); + console.log(chalk.green(`✓ Marked "${oldBook.title}" as read!`)); + + return updatedBooks; } + + + function getTotalBooks() { // TODO: Implement this function using length + const total = books.length; + console.log(chalk.blue(`\nTotal books: ${total}`)); + return total; } function hasUnreadBooks() { From 1788255c031c5842917403bbe9dade7e1be17679 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 19:46:34 +0100 Subject: [PATCH 09/15] added to print all books --- reading-list-manager/readingList.js | 36 ++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index 8ccdc3a..b79074f 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -147,22 +147,51 @@ function markAsRead(books, id) { -function getTotalBooks() { +function getTotalBooks(books) { // TODO: Implement this function using length const total = books.length; console.log(chalk.blue(`\nTotal books: ${total}`)); return total; } -function hasUnreadBooks() { +function hasUnreadBooks(books) { // TODO: Implement this function using some() + const hasUnread = books.some(function(book) { + return book.read === false; + }); + + if (hasUnread) { + console.log(chalk.yellow('You have books to read!')); + } else { + console.log(chalk.green('All books are read!')); + } + + return hasUnread; + } -function printAllBooks() { +function printAllBooks(books) { // TODO: Implement this function // Loop through and display with chalk // Use green for read books, yellow for unread // Use cyan for titles + console.log(chalk.blue('\n--- ALL BOOKS ---')); + + if (books.length === 0) { + console.log(chalk.yellow('No books yet!')); + return; + } + + for (let i = 0; i < books.length; i++) { + const book = books[i]; + let status; + if (book.read) { + status = chalk.green('✓ Read'); + } else { + status = chalk.red('○ Unread'); + } + console.log(`${book.id}. ${book.title} by ${book.author} - ${status}`); + } } function printSummary() { @@ -170,4 +199,5 @@ function printSummary() { // Show statistics with chalk // Display total books, read count, unread count // Use bold for stats + } \ No newline at end of file From 82c6adf025aad0441d588fbb927f29b0228b7392 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 20:12:09 +0100 Subject: [PATCH 10/15] prints summary at the end --- reading-list-manager/readingList.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index b79074f..3ae3020 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -194,10 +194,31 @@ function printAllBooks(books) { } } -function printSummary() { +function printSummary(books) { // TODO: Implement this function // Show statistics with chalk // Display total books, read count, unread count // Use bold for stats + console.log(chalk.blue('\n--- READING SUMMARY ---')); + + // Total books + const total = books.length; + console.log(`Total: ${total}`); + + // Count read books + let readCount = 0; + for (let i = 0; i < books.length; i++) { + if (books[i].read) { + readCount++; + } + } + const unreadCount = total - readCount; + + console.log(chalk.green(`Read: ${readCount}`)); + console.log(chalk.red(`Unread: ${unreadCount}`)); + +} + +module.exports = { } \ No newline at end of file From b331165caf9175a4a86505eeefbcd6056654c6e9 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 20:55:26 +0100 Subject: [PATCH 11/15] prints a summary of the list --- reading-list-manager/app.js | 25 ++++++++++++++++++++----- reading-list-manager/readingList.js | 15 +++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/reading-list-manager/app.js b/reading-list-manager/app.js index b0365ef..323cdc0 100644 --- a/reading-list-manager/app.js +++ b/reading-list-manager/app.js @@ -2,11 +2,26 @@ // node app.js // TODO: Implement the main application logic here -// 1. Load books on startup -// 2. Display all books -// 3. Show summary statistics -// 4. Add example of filtering by genre or read/unread status -// 5. Add example of marking a book as read +const readingList = require('./readingList'); +const chalk = require('chalk'); + +function main() { + console.log(chalk.blue('=== MY READING LIST ===')); + + // 1. Load books on startup + let myBooks = readingList.loadBooks(); + // 2. Display all books + readingList.showAllBooks(myBooks); + // 3. Show summary statistics + readingList.printSummary(myBooks); + // 4. Add example of filtering by genre or read/unread status + readingList.getBooksByGenre(myBooks); + // 5. Add example of marking a book as read + console.log(chalk.blue('/n === Marking a book as read ===')); + myBooks = readingList.markAsRead(myBooks); +} + +main(); console.log('📚 MY READING LIST 📚\n'); diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index 3ae3020..713e53e 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -220,5 +220,16 @@ function printSummary(books) { } module.exports = { - -} \ No newline at end of file + loadBooks, + saveBooks, + addBook, + getUnreadBooks, + getBooksByGenre, + markAsRead, + getTotalBooks, + hasUnreadBooks, + printAllBooks, + printSummary + + +}; \ No newline at end of file From 373c6abd09960d818898205f9dac84cc921a411a Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 22:22:25 +0100 Subject: [PATCH 12/15] fixed the filtering by genre error --- reading-list-manager/app.js | 4 +- reading-list-manager/books.json | 8 +- reading-list-manager/readingList.js | 144 ++++++++++++++-------------- 3 files changed, 78 insertions(+), 78 deletions(-) diff --git a/reading-list-manager/app.js b/reading-list-manager/app.js index 323cdc0..e4339d9 100644 --- a/reading-list-manager/app.js +++ b/reading-list-manager/app.js @@ -11,11 +11,11 @@ function main() { // 1. Load books on startup let myBooks = readingList.loadBooks(); // 2. Display all books - readingList.showAllBooks(myBooks); + readingList.printAllBooks(myBooks); // 3. Show summary statistics readingList.printSummary(myBooks); // 4. Add example of filtering by genre or read/unread status - readingList.getBooksByGenre(myBooks); + readingList.getBooksByGenre(myBooks, 'Fiction'); // 5. Add example of marking a book as read console.log(chalk.blue('/n === Marking a book as read ===')); myBooks = readingList.markAsRead(myBooks); diff --git a/reading-list-manager/books.json b/reading-list-manager/books.json index d0850c3..e889da3 100644 --- a/reading-list-manager/books.json +++ b/reading-list-manager/books.json @@ -1,7 +1,6 @@ [ - { - "id": 1, + "id": 1, "title": "1984", "author": "George Orwell", "genre": "Fiction", @@ -55,7 +54,4 @@ "genre": "Chess", "read": false } - - -] - +] \ No newline at end of file diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index 713e53e..bc346de 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -5,41 +5,46 @@ const chalk = require('chalk'); const FILE_NAME = 'books.json'; function loadBooks() { - // TODO: Implement this function - // Read from books.json - try{ - const data = fs.readdirSync(FILE_NAME,'utf8'); - return JSON.parse(data); - } - // Handle missing file (create empty array) - catch (error){ - if (error.code === 'ENOENT'){ - console.log(chalk.yellow('No books file found.Starting again')); - return[]; + try { + const content = fs.readFileSync('./books.json', 'utf8'); + const books = JSON.parse(content); + + if (!Array.isArray(books)) { + console.log(chalk.yellow('Books data was not an array – starting fresh')); + return []; + } + + return books; + } catch (error) { + if (error.code === 'ENOENT') { + console.log( + chalk.yellow('No books.json found. Starting with empty list.') + ); + return []; + } + if (error instanceof SyntaxError) { + console.log( + chalk.red( + 'Invalid JSON in books.json – file is broken. Starting fresh!' + ) + ); + return []; } - // Handle invalid JSON (notify user, use empty array) - if (error instanceof SyntaxError){ - console.log(chalk.red('Book file is broken. Starting fresh!')); - return[]; - } - //Use try-catch for error handling - console.log(chalk.red('Error loading books:'),error.message); - return[]; + console.log(chalk.red('Error loading books:'), error.message); + return []; } - } function saveBooks(books) { // TODO: Implement this function // Write books array to books.json // Use try-catch for error handling - try{ - const data =JSON.stringify(books,null,2); - fs.writeFileSync(FILE_NAME,data); + try { + const data = JSON.stringify(books, null, 2); + fs.writeFileSync(FILE_NAME, data); console.log(chalk.green('Saved :')); - } - catch (error){ - console.log(chalk.red('Save failed'),error.message); + } catch (error) { + console.log(chalk.red('Save failed'), error.message); } } @@ -51,26 +56,21 @@ function addBook(books, titles, author, genre) { title: title, author: author, genre: genre, - read: false + read: false, }; - books.push(newBook); - - + saveBooks(books); - - - console.log(chalk.green(`✓ Added "${title}"`)); - - return books; + console.log(chalk.green(`✓ Added "${title}"`)); + return books; } function getUnreadBooks(books) { // TODO: Implement this function using filter() - const unreadBooks = books.filter(function(book) { + const unreadBooks = books.filter(function (book) { return book.read === false; }); @@ -83,19 +83,31 @@ function getUnreadBooks(books) { console.log(`${book.id}. ${book.title} by ${book.author}`); } } - - return unreadBooks; - + return unreadBooks; } function getBooksByGenre(books, genre) { // TODO: Implement this function using filter() - const genreBooks = books.filter(function(book) { - return book.genre.toLowerCase() === genre.toLowerCase(); - }); + + console.log('DEBUG → books type:', typeof books); + console.log('DEBUG → is array?:', Array.isArray(books)); + console.log( + 'DEBUG → books length:', + books?.length ?? 'N/A (books not array)' + ); + + // Safe filter – prevents crash even if array has holes, undefined items, null, etc. + const genreBooks = books.filter( + (book) => + book && + typeof book === 'object' && // exists & is object (not null/undefined) + typeof book.genre === 'string' && // genre exists and is actually a string + book.genre.toLowerCase() === genre.toLowerCase() + ); console.log(chalk.blue(`\n--- ${genre} BOOKS ---`)); + if (genreBooks.length === 0) { console.log(chalk.yellow(`No ${genre} books!`)); } else { @@ -105,69 +117,64 @@ function getBooksByGenre(books, genre) { console.log(`${readStatus} ${book.id}. ${book.title} by ${book.author}`); } } - + return genreBooks; } function markAsRead(books, id) { // TODO: Implement this function using map() - const updatedBooks = books.map(function(book) { - + const updatedBooks = books.map(function (book) { if (book.id === id) { - return { + return { id: book.id, title: book.title, author: book.author, genre: book.genre, - read: true + read: true, }; } - + return book; }); //Does book exist? - const oldBook = books.find(function(book) { + const oldBook = books.find(function (book) { return book.id === id; }); - + if (!oldBook) { console.log(chalk.red(`✗ Book #${id} not found!`)); return books; } - + // Save changes saveBooks(updatedBooks); console.log(chalk.green(`✓ Marked "${oldBook.title}" as read!`)); - + return updatedBooks; } - - - function getTotalBooks(books) { // TODO: Implement this function using length - const total = books.length; + const total = books.length; console.log(chalk.blue(`\nTotal books: ${total}`)); return total; } function hasUnreadBooks(books) { // TODO: Implement this function using some() - const hasUnread = books.some(function(book) { + const hasUnread = books.some(function (book) { return book.read === false; }); - + if (hasUnread) { console.log(chalk.yellow('You have books to read!')); } else { console.log(chalk.green('All books are read!')); } - - return hasUnread; + return hasUnread; } function printAllBooks(books) { @@ -176,12 +183,12 @@ function printAllBooks(books) { // Use green for read books, yellow for unread // Use cyan for titles console.log(chalk.blue('\n--- ALL BOOKS ---')); - + if (books.length === 0) { console.log(chalk.yellow('No books yet!')); return; } - + for (let i = 0; i < books.length; i++) { const book = books[i]; let status; @@ -200,11 +207,11 @@ function printSummary(books) { // Display total books, read count, unread count // Use bold for stats console.log(chalk.blue('\n--- READING SUMMARY ---')); - + // Total books const total = books.length; console.log(`Total: ${total}`); - + // Count read books let readCount = 0; for (let i = 0; i < books.length; i++) { @@ -213,10 +220,9 @@ function printSummary(books) { } } const unreadCount = total - readCount; - + console.log(chalk.green(`Read: ${readCount}`)); console.log(chalk.red(`Unread: ${unreadCount}`)); - } module.exports = { @@ -229,7 +235,5 @@ module.exports = { getTotalBooks, hasUnreadBooks, printAllBooks, - printSummary - - -}; \ No newline at end of file + printSummary, +}; From f354c3d78aafa5d79eda5a7ec29693276ba291ef Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 22:32:41 +0100 Subject: [PATCH 13/15] marked 7 as read --- reading-list-manager/app.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/reading-list-manager/app.js b/reading-list-manager/app.js index e4339d9..e1d9bb6 100644 --- a/reading-list-manager/app.js +++ b/reading-list-manager/app.js @@ -5,6 +5,9 @@ const readingList = require('./readingList'); const chalk = require('chalk'); +console.log('📚 MY READING LIST 📚\n'); + +// Your implementation here function main() { console.log(chalk.blue('=== MY READING LIST ===')); @@ -22,7 +25,3 @@ function main() { } main(); - -console.log('📚 MY READING LIST 📚\n'); - -// Your implementation here From 2a28d43025ca744eb34434519a284028068bb424 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 22:33:13 +0100 Subject: [PATCH 14/15] marked 7 as read --- reading-list-manager/app.js | 2 +- reading-list-manager/books.json | 106 +++++++++++++++----------------- 2 files changed, 51 insertions(+), 57 deletions(-) diff --git a/reading-list-manager/app.js b/reading-list-manager/app.js index e1d9bb6..9532ba1 100644 --- a/reading-list-manager/app.js +++ b/reading-list-manager/app.js @@ -21,7 +21,7 @@ function main() { readingList.getBooksByGenre(myBooks, 'Fiction'); // 5. Add example of marking a book as read console.log(chalk.blue('/n === Marking a book as read ===')); - myBooks = readingList.markAsRead(myBooks); + myBooks = readingList.markAsRead(myBooks, 7); } main(); diff --git a/reading-list-manager/books.json b/reading-list-manager/books.json index e889da3..0d29e49 100644 --- a/reading-list-manager/books.json +++ b/reading-list-manager/books.json @@ -1,57 +1,51 @@ -[ - { - "id": 1, - "title": "1984", - "author": "George Orwell", - "genre": "Fiction", - "read": false - }, - - { - "id": 2, - "title": "The Havoc of Choice", - "author": "Wanjiru Koinange", - "genre": "African Literature", - "read": true - }, - - { - "id": 3, - "title": "CreepShow", - "author": "Stephen King", - "genre": "Comic", - "read": false - }, - - { - "id": 4, - "title": "Fire and Ice", - "author": "Erin Hunter", - "genre": "Fiction", - "read": true - }, - - { - "id": 5, - "title": "Toxic Bachelors", - "author": "Daniella Steel", - "genre": "Adult", - "read": false - }, - - { - "id": 6, - "title": "Foxes in a fix", - "author": "Bruce Cameron", - "genre": "Animals", - "read": true - }, - - { - "id": 7, - "title": "The Luzhin Defense", - "author": "Vladimir Nabokov", - "genre": "Chess", - "read": false - } +[ + { + "id": 1, + "title": "1984", + "author": "George Orwell", + "genre": "Fiction", + "read": false + }, + { + "id": 2, + "title": "The Havoc of Choice", + "author": "Wanjiru Koinange", + "genre": "African Literature", + "read": true + }, + { + "id": 3, + "title": "CreepShow", + "author": "Stephen King", + "genre": "Comic", + "read": false + }, + { + "id": 4, + "title": "Fire and Ice", + "author": "Erin Hunter", + "genre": "Fiction", + "read": true + }, + { + "id": 5, + "title": "Toxic Bachelors", + "author": "Daniella Steel", + "genre": "Adult", + "read": false + }, + { + "id": 6, + "title": "Foxes in a fix", + "author": "Bruce Cameron", + "genre": "Animals", + "read": true + }, + { + "id": 7, + "title": "The Luzhin Defense", + "author": "Vladimir Nabokov", + "genre": "Chess", + "read": true + } ] \ No newline at end of file From eaf966363b1166f1f4d0ea83385f45c1c89953c5 Mon Sep 17 00:00:00 2001 From: hannahwn Date: Wed, 18 Feb 2026 22:37:12 +0100 Subject: [PATCH 15/15] added cyan colour --- reading-list-manager/readingList.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/reading-list-manager/readingList.js b/reading-list-manager/readingList.js index bc346de..50707f5 100644 --- a/reading-list-manager/readingList.js +++ b/reading-list-manager/readingList.js @@ -197,7 +197,9 @@ function printAllBooks(books) { } else { status = chalk.red('○ Unread'); } - console.log(`${book.id}. ${book.title} by ${book.author} - ${status}`); + console.log( + `${book.id}.${chalk.cyan(book.title)} by ${book.author} - ${status}` + ); } }