Skip to content

Yana P.#2

Open
YanaP1312 wants to merge 3 commits into
HackYourAssignment:mainfrom
YanaP1312:main
Open

Yana P.#2
YanaP1312 wants to merge 3 commits into
HackYourAssignment:mainfrom
YanaP1312:main

Conversation

@YanaP1312
Copy link
Copy Markdown

No description provided.

@github-actions
Copy link
Copy Markdown

📝 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

@remarcmij remarcmij self-assigned this Mar 31, 2026
Copy link
Copy Markdown

@remarcmij remarcmij left a comment

Choose a reason for hiding this comment

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

Hi @YanaP1312, your queries from task 1 look good. In task 2, some functions do not completely mirror what the JSON versions do. Also, take note how boolean values should be treated.

Comment thread task-1/queries.sql
SELECT title, published_year FROM books
WHERE genre = "Science Fiction"
ORDER BY published_year ASC;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note that single quotes are preferred in SQL for string literals.

Comment thread task-1/queries.sql

SELECT title, published_year FROM books
WHERE published_year < 1950
ORDER BY published_year DESC;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fine, but no explicit order was asked for.

Comment thread task-1/queries.sql

SELECT b.title, b.published_year, b.genre, a.first_name || " " || a.last_name AS author FROM books b
JOIN authors a ON a.id=b.author_id
ORDER BY author, published_year;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No order was asked for, but your chosen order makes perfect sense.

Comment thread task-1/queries.sql

-- **Question 4** — List all books written by Stephen King. Show the title and published year, ordered by year. _(Hint: JOIN the two tables and filter on the author's name.)_

SELECT b.title, b.published_year, a.first_name || " " || a.last_name AS author FROM books b
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Author name was not asked for.

Comment thread task-1/queries.sql

SELECT b.title, b.published_year, a.first_name || " " || a.last_name AS author FROM books b
JOIN authors a ON a.id=b.author_id
WHERE a.first_name || " " || a.last_name = "Stephen King"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It is not necessary to create the full name for the WHERE clause.

Suggested change
WHERE a.first_name || " " || a.last_name = "Stephen King"
WHERE a.first_name = 'Stephen' AND a.last_name = 'King'

Comment thread task-2/src/database.js
Comment on lines +77 to +85
const existedCardsInfoForDeck = getAllCardsForDeck(deckId);

const existing = existedCardsInfoForDeck.find(
(card) => card.question === question && card.answer === answer
);

if (existing) {
return existing;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The JSON version does not check for an existing card. If you want to do this, try and SELECT a single card (imagine there may be millions of cards: you dont want to get them all just so you can filter them in JS).

Comment thread task-2/src/database.js
Comment on lines +93 to +95
return db
.prepare(`SELECT id, question FROM cards WHERE id = ?`)
.get(result.lastInsertRowid);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Alternatively, you can construct an object yourself, without the need to hit the database again:

Suggested change
return db
.prepare(`SELECT id, question FROM cards WHERE id = ?`)
.get(result.lastInsertRowid);
return {
id: Number(info.lastInsertRowid),
question,
answer,
learned: false,
deckId,
};

Comment thread task-2/src/database.js
// TODO: set learned = 1 for the card with the given id
// return the updated row, or null if not found
throw new Error('Not implemented');
db.prepare(`UPDATE cards SET learned = 1 WHERE id=?`).run(cardId);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The JSON version returns null if the card is not found.

Suggested change
db.prepare(`UPDATE cards SET learned = 1 WHERE id=?`).run(cardId);
const info = db
.prepare("UPDATE cards SET learned = 1 WHERE id = ?")
.run(cardId);
if (info.changes === 0) {
return null;
}```

Comment thread task-2/src/database.js
return {
id: card.id,
learned: card.learned === 1 ? 'true' : 'false',
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  1. The JSON version returns a complete car object (with learned as a boolean and a deckId instead of deck_id).
  2. true and false are boolean literals, not strings.

Comment thread task-2/src/database.js
// return true if a row was deleted, false otherwise
throw new Error('Not implemented');
const card = db.prepare(`DELETE FROM cards WHERE id=?`).run(cardId);
return card.changes > 0 ? 'true' : 'false';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
return card.changes > 0 ? 'true' : 'false';
return card.changes > 0;

@remarcmij remarcmij added the Reviewed This assignment has been reivewed by a mentor and a feedback has been provided label Apr 2, 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