Object oriented programming
Classes and objects
Encapsulation
Code style: clean code
LLMs
Tokenization
Inference
Tools
RAGs
Using LLMs in code
Practice
Assignment
Core program
Week 11 Assignment
Task 1: Time class
Create a class called Time that represents a time of day. The class tracks the a time using a single property: the number of seconds since midnight. It then calculates the hours, minutes, and seconds from this property.
For example:
| Seconds from midnight |
Current time |
| 0 |
00:00:00 |
| 3602 |
01:00:02 |
| 45296 |
12:34:56 |
| 86399 |
23:59:59 |
| < 0 |
Invalid |
| ≥ 86400 |
Invalid |
Requirements
Private properties
- secondsFromMidnight - The property that represents the current time in seconds passed from midnight. Min value is 0 and max value is 86399.
Public Methods
- constructor(hours, minutes, seconds) — sets
secondsFromMidnight according to the parameters.
- getHours() — returns the current hour.
- getMinutes() — returns the current minute.
- getSeconds() — returns the current second.
- addSeconds(seconds) — adds the specified number of seconds to the current time.
- addMinutes(minutes) — adds the specified number of minutes to the current time.
- addHours(hours) — adds the specified number of hours to the current time.
- toString() — returns the current time as a string in
HH:mm:ss format. (Hint: use padStart to add leading zeros if needed.)
Logic for addSeconds, addMinutes, and addHours
seconds, minutes, and hours can be negative, allowing you to subtract time.
- If
secondsFromMidnight exceeds 86399, it rolls over to 0.
For example: 86000 + 6000 = 92000 → 5600
(Hint: use the % operator).
- If
secondsFromMidnight becomes negative, it rolls over to 86399.
For example: 1000 - 2000 = -1000 → 85400
Example usage
const myTime = new Time(12, 35, 0);
console.log(myTime.toString()); // 12:35:00
myTime.getHours(); // 12
myTime.getMinutes(); // 35
myTime.getSeconds(); // 0
myTime.addMinutes(25);
console.log(myTime.toString()); // 13:00:00
myTime.addHours(12);
console.log(myTime.toString()); // 01:00:00
Unit tests
A unit test suite has been written to help out with the implementation. Run it with npm test . Feel free to take a look at the implementation of the tests or add your own.
Task 2: AI powered quiz game
Build a quiz app where an LLM generates the questions. The player sees one question at a time with four possible answers. They type the correct answer (1, 2, 3, or 4), and the application shows whether they answered correctly.
- A correct answer message will be shown in green and award the player 1 point.
- A wrong answer message will be shown in red, mention the correct answer, and award no points.
The quiz will end after 10 questions and show the final score at the end.
Requirements
- Generate questions and answers using an LLM via HTTP API. Use the built-in
fetch or the openai npm package.
- Show the player one question at a time with four possible answers.
- Check the correct answer locally without using the LLM.
- Track the score and display it at the end.
- Choose your own question topics, CLI messages, and colours.
<aside>
❗
Never push your GitHub token to GitHub. Use .gitignore or environment variables.
If you accidentally push a token to GitHub, revoke it immediately and generate a new one.
</aside>
Tips & Guidance
- Craft a prompt that explains what you want to do, including the exact response format that works best for you. Test different prompts. (Review Using LLMs in code )
- Choose any topic for your quiz - feel free to be creative. Ideas for topics: Geography, Dutch, Music, Movies, quantum physics.
- Ask the LLM to generate all 10 questions in one reply before the start of the quiz.
- Use the GitHub Models playground or any other AI chatbot to test your prompts.
- Rate limit tips
- Use a low-tier model to get more requests per day. (e.g:
openai/gpt-4.1-mini)
- When testing your code, skip the HTTP call to the API and return fake JSON data instead. This helps you test without using your request quota.
- For testing your prompt, use a different AI chat like ChatGPT.
Bonus
- Add hints: The player can type
h to remove two incorrect answers
- Ask the user upfront for any quiz topic or to pick from a pre-defined list of topics
- Add difficulty levels: Start with easy questions and gradually increase the difficulty
Submission
Follow the Assignment submission guide to learn how to submit the assignment
The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0
*https://hackyourfuture.net/*

Built with ❤️ by the HackYourFuture community · Thank you, contributors
Found a mistake or have a suggestion? Let us know in the feedback form.