Skip to content

Monerh A#2

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

Monerh A#2
Miuroro wants to merge 3 commits intoHackYourAssignment:mainfrom
Miuroro:main

Conversation

@Miuroro
Copy link
Copy Markdown

@Miuroro Miuroro commented Mar 25, 2026

No description provided.

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 @Miuroro, all looks good. Some minor comments, but overall, well done!

throw new Error("Invalid time");
}

this.#secondsFromMidnight = totalSeconds;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice input validation.

Although the numeric constants are not that difficult to reason about, it would be even clearer if you created a couple of constants for these "magic" numbers and then used them throughout your code. For instance:

const SEC_PER_MINUTE = 60;
const SEC_PER_HOUR = 60 * SEC_PER_MINUTE;
const SEC_PER_DAY = 24 * SEC_PER_HOUR;

"questions" must contain exactly 10 items.
Each answers array must contain exactly 4 non-empty strings in random order.
"correct" must be an integer 1-4 and must match the correct option after randomization.
If any item is invalid, regenerate the full response until valid.`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good prompt. Tells the LLM exactly what it should generate.

If any item is invalid, regenerate the full response until valid.`;

export async function runQuiz({ openai, input, promptText = buildPrompt() }) {
const response = await openai.chat.completions.create({
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You are not handling errors (try/catch). The API may throw an error for whatever reason.

let score = 0;
for (let i = 0; i < questions.length; i++) {
const currentQuestion = questions[i];
console.log(chalk.blue(`Loading question ${i + 1}...`));
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 message "Loading question" is unneeded. You are just accessing an element from an array, and the next console.log already shows that question.

let answer;
while (true) {
answer = input("Answer (1-4): ");
if (answer === null) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: If I enter 9 correct answers and then accidentally hit the Enter key only, I will be sad 😞 . Maybe ask "Are you sure?" before exiting?

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