From c910c5e712f0c3c9b973d9eb8652a0e9ce7af142 Mon Sep 17 00:00:00 2001 From: baraah Date: Wed, 25 Mar 2026 11:21:58 +0100 Subject: [PATCH 1/2] first task completed --- task-1/Time.js | 70 +++++++++++++++++++++++++++++++++++++++- task-1/package-lock.json | 32 ++---------------- 2 files changed, 71 insertions(+), 31 deletions(-) diff --git a/task-1/Time.js b/task-1/Time.js index 97ca7e2..99378e8 100644 --- a/task-1/Time.js +++ b/task-1/Time.js @@ -1,3 +1,71 @@ export class Time { // Your code here -} \ No newline at end of file + #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(){ + return Math.floor(this.#secondsFromMidnight / 3600); +} + +getMinutes(){ +return Math.floor((this.#secondsFromMidnight % 3600) / 60); +} + +getSeconds(){ + return this.#secondsFromMidnight % 60; +} + +addSeconds(seconds) { + this.#secondsFromMidnight = (this.#secondsFromMidnight + seconds) % 86400; + + if (this.#secondsFromMidnight < 0) { + this.#secondsFromMidnight += 86400; + } +} + +addMinutes(minutes){ + this.addSeconds(minutes * 60); +} + +addHours(hours){ + this.addSeconds(hours * 3600); +} + +toString() { + const h = String(this.getHours()).padStart(2, "0"); + const m = String(this.getMinutes()).padStart(2, "0"); + const s = String(this.getSeconds()).padStart(2, "0"); + + return `${h}:${m}:${s}`; +} + +} +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(35); +console.log(myTime.toString()); // 13:00:00 + +myTime.addHours(12); +console.log(myTime.toString()); // 01:00:00 + + +const t = new Time(23, 59, 50); +t.addSeconds(15); +console.log(t.toString()); // 00:00:05 + +const t2 = new Time(0, 0, 5); +t2.addSeconds(-10); +console.log(t2.toString()); // 23:59:55 diff --git a/task-1/package-lock.json b/task-1/package-lock.json index aba2728..14d0d66 100644 --- a/task-1/package-lock.json +++ b/task-1/package-lock.json @@ -161,9 +161,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -180,9 +177,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -199,9 +193,6 @@ "cpu": [ "ppc64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -218,9 +209,6 @@ "cpu": [ "s390x" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -237,9 +225,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MIT", "optional": true, "os": [ @@ -256,9 +241,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MIT", "optional": true, "os": [ @@ -706,9 +688,6 @@ "cpu": [ "arm64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -729,9 +708,6 @@ "cpu": [ "arm64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -752,9 +728,6 @@ "cpu": [ "x64" ], - "libc": [ - "glibc" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -775,9 +748,6 @@ "cpu": [ "x64" ], - "libc": [ - "musl" - ], "license": "MPL-2.0", "optional": true, "os": [ @@ -885,6 +855,7 @@ "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -1032,6 +1003,7 @@ "resolved": "https://registry.npmjs.org/vite/-/vite-8.0.2.tgz", "integrity": "sha512-1gFhNi+bHhRE/qKZOJXACm6tX4bA3Isy9KuKF15AgSRuRazNBOJfdDemPBU16/mpMxApDPrWvZ08DcLPEoRnuA==", "license": "MIT", + "peer": true, "dependencies": { "lightningcss": "^1.32.0", "picomatch": "^4.0.3", From 3d3038ffe1e1bb509f59f4f55569d315df1393cb Mon Sep 17 00:00:00 2001 From: baraah Date: Wed, 25 Mar 2026 22:04:03 +0100 Subject: [PATCH 2/2] task 2 --- .gitignore | 2 + task-2/index.js | 87 ++++++++++++++++++++++++++++++++++++++++ task-2/package-lock.json | 73 +++++++++++++++++++++++++++++++++ task-2/package.json | 10 ++++- 4 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 task-2/package-lock.json diff --git a/.gitignore b/.gitignore index 2b76d7c..8725d56 100644 --- a/.gitignore +++ b/.gitignore @@ -156,3 +156,5 @@ dist vite.config.js.timestamp-* vite.config.ts.timestamp-* +node_modules +.env \ No newline at end of file diff --git a/task-2/index.js b/task-2/index.js index 02acffa..d9c9d9f 100644 --- a/task-2/index.js +++ b/task-2/index.js @@ -1 +1,88 @@ // Write your code here. You may create as many files as you like. + +import readlineSync from "readline-sync"; +import chalk from "chalk"; + +//using fake JSON for testing +const questions = [ + { + question: "What country is Zara from?", + options: ["France", "Spain", "Italy", "Germany"], + correctAnswer: 2, + }, + { + question: "Chanel is from?", + options: ["Italy", "France", "USA", "Spain"], + correctAnswer: 2, + }, + { + question: "Bershka originates from?", + options: ["Spain", "Germany", "France", "UK"], + correctAnswer: 1, + }, + { + question: "Volkswagen is from?", + options: ["Germany", "Italy", "Japan", "USA"], + correctAnswer: 1, + }, + { + question: "Nike is from?", + options: ["USA", "UK", "Germany", "France"], + correctAnswer: 1, + }, + { + question: "Adidas is from?", + options: ["Germany", "USA", "France", "Italy"], + correctAnswer: 1, + }, + { + question: "Gucci is from?", + options: ["Italy", "France", "Spain", "UK"], + correctAnswer: 1, + }, + { + question: "H&M is from?", + options: ["Sweden", "Norway", "Germany", "Denmark"], + correctAnswer: 1, + }, + { + question: "Puma is from?", + options: ["Germany", "USA", "Italy", "France"], + correctAnswer: 1, + }, + { + question: "Louis Vuitton is from?", + options: ["France", "Italy", "Spain", "UK"], + correctAnswer: 1, + }, +]; + + +let score = 0; + +console.log(chalk.blue("🎮 Welcome to the Brand Quiz Game!\n")); + +for (let i = 0; i < questions.length; i++) { + const q = questions[i]; + + console.log(chalk.yellow(`Question ${i + 1}: ${q.question}`)); + + for (let j = 0; j < q.options.length; j++) { + console.log(`${j + 1}. ${q.options[j]}`); + } + + const answer = readlineSync.question("Your answer (1-4): "); + + if (parseInt(answer) === q.correctAnswer) { + console.log(chalk.green("✅ Correct! +1 point\n")); + score++; + } else { + console.log( + chalk.red( + `❌ Wrong! Correct answer: ${q.options[q.correctAnswer - 1]}\n` + ) + ); + } +} + +console.log(chalk.blue(`🎯 Your final score: ${score}/10`)); \ No newline at end of file diff --git a/task-2/package-lock.json b/task-2/package-lock.json new file mode 100644 index 0000000..d5bfb03 --- /dev/null +++ b/task-2/package-lock.json @@ -0,0 +1,73 @@ +{ + "name": "task-2", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "task-2", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "chalk": "^5.6.2", + "dotenv": "^17.3.1", + "openai": "^6.32.0", + "readline-sync": "^1.4.10" + } + }, + "node_modules/chalk": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", + "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/dotenv": { + "version": "17.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.3.1.tgz", + "integrity": "sha512-IO8C/dzEb6O3F9/twg6ZLXz164a2fhTnEWb95H23Dm4OuN+92NmEAlTrupP9VW6Jm3sO26tQlqyvyi4CsnY9GA==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/openai": { + "version": "6.32.0", + "resolved": "https://registry.npmjs.org/openai/-/openai-6.32.0.tgz", + "integrity": "sha512-j3k+BjydAf8yQlcOI7WUQMQTbbF5GEIMAE2iZYCOzwwB3S2pCheaWYp+XZRNAch4jWVc52PMDGRRjutao3lLCg==", + "license": "Apache-2.0", + "bin": { + "openai": "bin/cli" + }, + "peerDependencies": { + "ws": "^8.18.0", + "zod": "^3.25 || ^4.0" + }, + "peerDependenciesMeta": { + "ws": { + "optional": true + }, + "zod": { + "optional": true + } + } + }, + "node_modules/readline-sync": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz", + "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==", + "license": "MIT", + "engines": { + "node": ">= 0.8.0" + } + } + } +} diff --git a/task-2/package.json b/task-2/package.json index a992f45..28b813a 100644 --- a/task-2/package.json +++ b/task-2/package.json @@ -9,5 +9,11 @@ "keywords": [], "author": "", "license": "ISC", - "type": "module" -} \ No newline at end of file + "type": "module", + "dependencies": { + "chalk": "^5.6.2", + "dotenv": "^17.3.1", + "openai": "^6.32.0", + "readline-sync": "^1.4.10" + } +}