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
6 changes: 6 additions & 0 deletions package-lock.json

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

54 changes: 53 additions & 1 deletion task-1/Time.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,55 @@
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 time");
}

this.#secondsFromMidnight = totalSeconds;
}

// 🟢 getters
getHours() {
return Math.floor(this.#secondsFromMidnight / 3600);
}

getMinutes() {
return Math.floor((this.#secondsFromMidnight % 3600) / 60);
}

getSeconds() {
return this.#secondsFromMidnight % 60;
}

// 🟢 normalize helper
#normalize() {
this.#secondsFromMidnight =
((this.#secondsFromMidnight % 86400) + 86400) % 86400;
}

// 🟢 add methods
addSeconds(seconds) {
this.#secondsFromMidnight += seconds;
this.#normalize();
}

addMinutes(minutes) {
this.addSeconds(minutes * 60);
}

addHours(hours) {
this.addSeconds(hours * 3600);
}

// 🟢 format as HH:mm:ss
toString() {
const hh = String(this.getHours()).padStart(2, "0");
const mm = String(this.getMinutes()).padStart(2, "0");
const ss = String(this.getSeconds()).padStart(2, "0");

return `${hh}:${mm}:${ss}`;
}
}
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.

87 changes: 87 additions & 0 deletions task-2/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,88 @@
// Write your code here. You may create as many files as you like.
import chalk from 'chalk';
import readlineSync from 'readline-sync';

// 📝 Quiz questions (fake JSON for testing, can replace with API later)
const questions = [
{
question: "What is the largest planet in our solar system?",
answers: ["Earth", "Mars", "Jupiter", "Saturn"],
correct: 3
},
{
question: "What is the capital of France?",
answers: ["Paris", "Rome", "Madrid", "Berlin"],
correct: 1
},
{
question: "Which chemical element has the symbol O?",
answers: ["Gold", "Oxygen", "Iron", "Hydrogen"],
correct: 2
},
{
question: "Who wrote the novel '1984'?",
answers: ["George Orwell", "Tolstoy", "Shakespeare", "Mark Twain"],
correct: 1
},
{
question: "What is the fastest land animal?",
answers: ["Cheetah", "Lion", "Gazelle", "Kangaroo"],
correct: 1
},
{
question: "Which is the largest ocean on Earth?",
answers: ["Atlantic Ocean", "Pacific Ocean", "Indian Ocean", "Arctic Ocean"],
correct: 2
},
{
question: "Which country uses the Euro as its currency?",
answers: ["United Kingdom", "Sweden", "Spain", "Switzerland"],
correct: 3
},
{
question: "Which organ pumps blood throughout the body?",
answers: ["Liver", "Lungs", "Heart", "Stomach"],
correct: 3
},
{
question: "Which animal is known as the 'King of the Jungle'?",
answers: ["Tiger", "Lion", "Elephant", "Leopard"],
correct: 2
},
{
question: "What is the fastest type of light?",
answers: ["X-rays", "Visible light", "Laser", "Light itself"],
correct: 4
}
];

// 🟢 Start the game
console.log(chalk.blue("Welcome to the Quiz Game!"));
console.log("Answer 10 questions by typing the number of your choice (1-4).");

let score = 0;

for (let i = 0; i < questions.length; i++) {
const q = questions[i];
console.log(`\nQuestion ${i + 1}: ${q.question}`);
q.answers.forEach((ans, index) => {
console.log(`${index + 1}. ${ans}`);
});

let answer;
while (true) {
answer = readlineSync.question("Your answer (1-4): ");
if (["1","2","3","4"].includes(answer)) break;
console.log(chalk.yellow("Please enter a number from 1 to 4."));
}

if (parseInt(answer) === q.correct) {
console.log(chalk.green("Correct!"));
score++;
} else {
console.log(chalk.red(`Wrong! The correct answer is: ${q.answers[q.correct - 1]}`));
}
}

// 🟢 End of game
console.log(chalk.blue(`\nGame Over! Your final score: ${score}/${questions.length}`));
38 changes: 38 additions & 0 deletions task-2/package-lock.json

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

8 changes: 6 additions & 2 deletions task-2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
"keywords": [],
"author": "",
"license": "ISC",
"type": "module"
}
"type": "module",
"dependencies": {
"chalk": "^5.6.2",
"readline-sync": "^1.4.10"
}
}