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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ web_modules/
.env.*
!.env.example


# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
Expand Down
72 changes: 70 additions & 2 deletions task-1/Time.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,71 @@
export class Time {
// Your code here
}
#secondsFromMidnight;
constructor(hours, minutes, seconds) {
const totalSeconds = hours * 3600 + minutes * 60 + seconds;
if (totalSeconds < 0 || totalSeconds >= 86400) {
throw new Error("Invalid");
}
this.#secondsFromMidnight = totalSeconds;
}
getHours() {
let resultHours = Math.floor(this.#secondsFromMidnight / 3600);
return resultHours;
}
getMinutes() {
let resultMinutes = Math.floor((this.#secondsFromMidnight % 3600) / 60);
return resultMinutes;
}
getSeconds() {
let resultSeconds = Math.floor(this.#secondsFromMidnight % 60);
return resultSeconds;
}
addSeconds(seconds) {
let currentTime = this.#secondsFromMidnight;
let newTotalSeconds = currentTime + seconds;
newTotalSeconds= newTotalSeconds % 86400;
if (newTotalSeconds < 0) {
newTotalSeconds += 86400;
}
this.#secondsFromMidnight= newTotalSeconds;
}
addMinutes(minutes) {
let currentTime = this.#secondsFromMidnight;
let newTotalMinutes = currentTime + (minutes * 60);
newTotalMinutes = newTotalMinutes % 86400;
if (newTotalMinutes < 0){
newTotalMinutes += 86400;
}
this.#secondsFromMidnight = newTotalMinutes;
}
addHours(hours) {
let currentTime = this.#secondsFromMidnight;
let newTotalHours = currentTime + (hours * 3600);
newTotalHours = newTotalHours % 86400;
if(newTotalHours < 0){
newTotalHours += 86400;
}
this.#secondsFromMidnight= newTotalHours;
}
toString() {
let seconds = this.getSeconds()
let minutes = this.getMinutes()
let hours = this.getHours()
seconds = String(seconds).padStart(2, '0');
minutes = String(minutes).padStart(2, '0');
hours = String(hours).padStart(2, '0');
let combine = [hours, minutes, seconds].join(':');
return combine;
}
}

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
32 changes: 2 additions & 30 deletions task-1/package-lock.json

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

151 changes: 150 additions & 1 deletion task-2/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,150 @@
// Write your code here. You may create as many files as you like.
import OpenAI from "openai";
import chalk from "chalk";
import dotenv from "dotenv";
dotenv.config();
import promptSync from "prompt-sync";
const prompt = promptSync();

const openai = new OpenAI({
baseURL: "https://models.github.ai/inference/",
apiKey: process.env.GITHUB_TOKEN,
//apiKey: process.env.OPENAI_API_KEY,
});

let countScore = 0;
// Here I was trying to understand how it works without Ai.
/*const question1 = {
text: "What is the largest planet in our solar system?",
answers: ["Earth", "Jupiter", "Mars", "Saturn"],
correct: 2,
};
const question2 = {
text: "Who wrote the play Romeo and Juliet?",
answers: [
"William Shakespeare",
"Charles Dickens",
"Jane Austen",
"Mark Twain",
],
correct: 1,
};

const question3 = {
text: "What is the chemical symbol for gold?",
answers: ["Au", "Ag", "Go", "Ga"],
correct: 1,
};

const question4 = {
text: "What is the capital of Japan?",
answers: ["Beijing", "Seoul", "Tokyo", "Bangkok"],
correct: 3,
};
const question5 = {
text: "Which organ in the human body produces insulin?",
answers: ["Liver", "Pancreas", "Kidney", "Heart"],
correct: 2,
};
const question6 = {
text: "What is the hardest natural substance on Earth?",
answers: ["Diamond", "Quartz", "Iron", "Topaz"],
correct: 1,
};

const question7 = {
text: "Who painted the Mona Lisa?",
answers: [
"Vincent van Gogh",
"Leonardo da Vinci",
"Pablo Picasso",
"Michelangelo",
],
correct: 2,
};
const question8 = {
text: "What gas do plants absorb from the atmosphere during photosynthesis?",
answers: ["Oxygen", "Carbon dioxide", "Nitrogen", "Hydrogen"],
correct: 2,
};
const question9 = {
text: "How many continents are there on Earth?",
answers: ["5", "6", "7", "8"],
correct: 3,
};

const question10 = {
text: "Which element is most abundant in the Earth’s crust?",
answers: ["Oxygen", "Silicon", "Aluminum", "Iron"],
correct: 1,
};*/
/*const questions = [
question1,
question2,
question3,
question4,
question5,
question6,
question7,
question8,
question9,
question10,
];*/
const topic = prompt("Choose a topic (e.g. sports, science): ");
const response = await openai.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [
{
role: "user",
content: `Generate 10 quiz questions about ${topic}.

Difficulty:
- Questions 1–3: easy
- Questions 4–7: medium
- Questions 8–10: hard

Return ONLY valid JSON (no text, no explanation).

Format:
[
{
"text": "Question here",
"answers": ["A", "B", "C", "D"],
"correct": 1
}
]

Rules:
- "answers" must have exactly 4 items
- "correct" must be a number from 1 to 4
- Do not include numbering like "1." inside answers
`,
},
],
});

const responseContent = response.choices[0].message.content;
const questions = JSON.parse(responseContent);
questions.forEach((question) => {
console.log(question.text);
question.answers.forEach((answer, index) => {
console.log(index + 1 + ". " + answer);
});
let userAnswer = prompt("Your answer: ");
userAnswer = Number(userAnswer);
while (userAnswer < 1 || userAnswer > 4 || isNaN(userAnswer)) {
userAnswer = Number(prompt("Please enter a number between 1 and 4: "));
}
if (userAnswer === question.correct) {
countScore += 1;
console.log(chalk.green("Well Done!"));
} else {
//countScore -= 1;
console.log(
chalk.red(
`Wrong Answer. Correct answer is: ${question.correct}`,
),
);
}
console.log("\n");
});
console.log(chalk.yellow("Your score: " + countScore + "/10"));