-
Notifications
You must be signed in to change notification settings - Fork 18
Baraah A. #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Baraah A. #12
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,3 +156,5 @@ dist | |
| vite.config.js.timestamp-* | ||
| vite.config.ts.timestamp-* | ||
|
|
||
| node_modules | ||
| .env | ||
| 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(){ | ||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment is misleading; it should be 01:10: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 | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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. | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No LLM API call |
||
| 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`)); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is misleading; it should be 13:10:00