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
17 changes: 17 additions & 0 deletions Sprint-2/interpret/invert.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const invert = require("./invert.js");

test("inverts a single key-value pair", () => {
expect(invert({ a: 1 })).toEqual({ 1: "a" });
});

test("inverts multiple key-value pairs", () => {
expect(invert({ a: 1, b: 2 })).toEqual({ 1: "a", 2: "b" });
});

test("handles empty objects", () => {
expect(invert({})).toEqual({});
});

test("handles string values", () => {
expect(invert({ x: "hello" })).toEqual({ hello: "x" });
});
36 changes: 35 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,38 @@
function setAlarm() {}
function setAlarm() {
const input = document.getElementById("alarmSet");
const heading = document.getElementById("timeRemaining");

let remainingSeconds = Number(input.value);

function formatTime(totalSeconds) {
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;

const mm = String(minutes).padStart(2, "0");
const ss = String(seconds).padStart(2, "0");

return `${mm}:${ss}`;
}

heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;

const intervalId = setInterval(() => {
remainingSeconds -= 1;

if (remainingSeconds > 0) {
heading.innerText = `Time Remaining: ${formatTime(remainingSeconds)}`;
} else {
heading.innerText = "Time Remaining: 00:00";
clearInterval(intervalId);
playAlarm();
document.body.classList.add("flash");
}
}, 1000);
}

function stopFlashingBackground() {
document.body.classList.remove("flash");
}

// DO NOT EDIT BELOW HERE

Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Title here</title>
<title>Alarm clock app</title>
</head>
<body>
<div class="centre">
Expand Down
10 changes: 10 additions & 0 deletions Sprint-3/alarmclock/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@
h1 {
text-align: center;
}

.flash {
animation: flash-bg 0.5s infinite alternate;
}

@keyframes flash-bg {
from { background-color: white; }
to { background-color: red; }
}

2 changes: 1 addition & 1 deletion Sprint-3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/user-event": "^14.6.1",
"jest": "^30.0.4",
"jest": "^28.1.3",
"jest-environment-jsdom": "^30.0.4"
}
}
Loading