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
2 changes: 1 addition & 1 deletion .hyf/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Auto grade tool

## How it works

1. The auto grade tool runs the `test.sh` script located in this directory.
2. `test.sh` should write to a file named `score.json` with following JSON format:
```json
Expand All @@ -12,4 +13,3 @@
```
All scores are out of 100. It is up to the assignment to determine how to calculate the score.
3. The auto grade runs via a github action on PR creation and updates the PR with the score.

2 changes: 1 addition & 1 deletion .hyf/score.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"score": 75,
"pass": true,
"passingScore": 50
}
}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 80
}
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Core program week 6 assignment

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

## Implementation Instructions
- Implement the requirements in the `reading-list-manager` folder.
- Use the existing file structure.
- You are allowed to create additional files if needed.

- Implement the requirements in the `reading-list-manager` folder.
- Use the existing file structure.
- You are allowed to create additional files if needed.
105 changes: 105 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"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/MunaNasher/c55-core-week-6.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"bugs": {
"url": "https://github.com/MunaNasher/c55-core-week-6/issues"
},
"homepage": "https://github.com/MunaNasher/c55-core-week-6#readme",
"dependencies": {
"chalk": "^4.1.2"
},
"devDependencies": {
"prettier": "^3.8.1"
}
}
13 changes: 12 additions & 1 deletion reading-list-manager/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
const {
printAllBooks,
printSummary,
getUnreadBooks,
getBooksByGenre,
markAsRead,
addBook,
} = require('./readingList.js'); // تأكدي من المسار صحيح

// This is the entrypoint for your application.
// node app.js

Expand All @@ -10,4 +19,6 @@

console.log('📚 MY READING LIST 📚\n');

// Your implementation here
printAllBooks();

printSummary();
38 changes: 37 additions & 1 deletion reading-list-manager/books.json
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
[]
[
{
"id": 1,
"title": "1984",
"author": "George Orwell",
"genre": "Fiction",
"read": false
},
{
"id": 2,
"title": "Dune",
"author": "Frank Herbert",
"genre": "Sci-Fi",
"read": true
},
{
"id": 3,
"title": "The Hobbit",
"author": "J.R.R. Tolkien",
"genre": "Fantasy",
"read": false
},
{
"id": 4,
"title": "Clean Code",
"author": "Robert C. Martin",
"genre": "Programming",
"read": true
},
{
"id": 5,
"title": "Atomic Habits",
"author": "James Clear",
"genre": "Self-Help",
"read": false
}
]
96 changes: 73 additions & 23 deletions reading-list-manager/readingList.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,103 @@
// Place here the file operation functions for loading and saving books
module.exports = {
loadBooks,
saveBooks,
addBook,
getUnreadBooks,
getBooksByGenre,
markAsRead,
getTotalBooks,
hasUnreadBooks,
printAllBooks,
printSummary,
};

const fs = require('fs');
function loadBooks() {
// TODO: Implement this function
// Read from books.json
// Handle missing file (create empty array)
// Handle invalid JSON (notify user, use empty array)
// Use try-catch for error handling
try {
const dataBuffer = fs.readFileSync('books.json');
const dataJSON = dataBuffer.toString();
return JSON.parse(dataJSON);
} catch (error) {
return [];
}
}

function saveBooks(books) {
// TODO: Implement this function
// Write books array to books.json
// Use try-catch for error handling
try {
const dataJSON = JSON.stringify(books, null, 2);
fs.writeFileSync('books.json', dataJSON);
} catch (error) {
console.log('❌ Error saving data:', error.message);
}
}

function addBook(book) {
// TODO: Implement this function
const books = loadBooks();
books.push(book);
saveBooks(books);
console.log(`✅ The book "${book.title}" was added successfully!`);
}

function getUnreadBooks() {
// TODO: Implement this function using filter()
const books = loadBooks();
return books.filter((book) => !book.read);
}

function getBooksByGenre(genre) {
// TODO: Implement this function using filter()
const books = loadBooks();
return books.filter((book) => book.genre === genre);
}

function markAsRead(id) {
// TODO: Implement this function using map()
const books = loadBooks();

const updatedBooks = books.map((book) => {
if (book.id === id) {
return { ...book, read: true };
}
return book;
});

saveBooks(updatedBooks);
}

function getTotalBooks() {
// TODO: Implement this function using length
const books = loadBooks();
return books.length;
}

function hasUnreadBooks() {
// TODO: Implement this function using some()
const books = loadBooks();
return books.some((book) => !book.read);
}

const chalk = require('chalk');
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();

books.forEach((book) => {
const status = book.read ? chalk.green('✓ Read') : chalk.yellow('⚠ Unread');

console.log(
chalk.cyan(book.title),
'by',
book.author,
`(${book.genre})`,
status
);
});
}

function printSummary() {
// TODO: Implement this function
// Show statistics with chalk
// Display total books, read count, unread count
// Use bold for stats
}
const books = loadBooks();

const total = books.length;
const read = books.filter((book) => book.read).length;
const unread = total - read;

console.log(chalk.bold('\n📊 SUMMARY 📊'));
console.log('Total Books:', total);
console.log('Read:', read);
console.log('Unread:', unread);
}