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 @@ -156,3 +156,4 @@ dist
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

.env
63 changes: 63 additions & 0 deletions package-lock.json

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

26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "c55-core-week-11",
"version": "1.0.0",
"description": "The week 11 assignment for the HackYourFuture Core program can be found at the following link: https://hub.hackyourfuture.nl/core-program-week-11-assignment",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dianadenwik/c55-core-week-11.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"bugs": {
"url": "https://github.com/dianadenwik/c55-core-week-11/issues"
},
"homepage": "https://github.com/dianadenwik/c55-core-week-11#readme",
"dependencies": {
"chalk": "^5.6.2",
"dotenv": "^17.3.1",
"openai": "^6.32.0"
}
}
58 changes: 56 additions & 2 deletions task-1/Time.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
export class Time {
// Your code here
}

#secondsFromMidnight;

constructor(hours, minutes, seconds) {
const total = hours * 3600 + minutes * 60 + seconds;

if (total < 0 || total >= 86400) {
throw new Error("Invalid");
}

this.#secondsFromMidnight = total;
}

getHours() {
const hours = Math.floor(this.#secondsFromMidnight / 3600);
return hours;
}

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

getSeconds(){
const seconds = Math.floor(this.#secondsFromMidnight % 60)
return seconds
}

addSeconds(seconds) {
const total = this.#secondsFromMidnight + seconds;

if (total >= 86400) {
this.#secondsFromMidnight = total % 86400;
} else if (total < 0) {
this.#secondsFromMidnight = total + 86400;
} else {
this.#secondsFromMidnight = total;
}
}
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}`
}
}

3 changes: 2 additions & 1 deletion task-1/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Time } from './Time.js';
import { Time } from "./Time.js";


const time = new Time(13, 37, 0);
console.log(time.toString()); // Output: "13:37:00"
Loading