Conversation
| throw new Error("Invalid time"); | ||
| } | ||
|
|
||
| this.#secondsFromMidnight = totalSeconds; |
There was a problem hiding this comment.
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.`; |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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}...`)); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
No description provided.