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
39 changes: 39 additions & 0 deletions Sprint-3/alarmclock/Module-Data-Groups.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"folders": [
{
"path": "../.."
},
{
"name": "Sprint-1",
"path": "../../Sprint-1"
},
{
"name": "Sprint-2",
"path": "../../Sprint-2"
},
{
"name": "Sprint-3",
"path": ".."
},
{
"name": "slideshow",
"path": "../slideshow"
},
{
"name": "reading-list",
"path": "../reading-list"
},
{
"name": "alarmclock",
"path": "."
},
{
"name": "todo-list",
"path": "../todo-list"
},
{
"name": "quote-generator",
"path": "../quote-generator"
}
]
}
33 changes: 32 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
function setAlarm() {}
let countdown;
let remainingTime = 0;

function setAlarm() {
const input = document.getElementById("alarmSet");
const seconds = parseInt(input.value, 10);
Comment on lines +4 to +6
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intentadion of the code seems incorrect. How can you ensure that the format is always consistent based on agreed rules?

if (isNaN(seconds) || seconds <= 0) return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice validation of the user input. Its important to always validate the user data.

How could you inform the user about that the input is invalid?


clearInterval(countdown);
remainingTime = seconds;

const display = document.getElementById("timeRemaining");
display.textContent = `Time Remaining: ${formatTime(remainingTime)}`;

countdown = setInterval(() => {
remainingTime--;
display.textContent = `Time Remaining: ${formatTime(remainingTime)}`;

if (remainingTime <= 0) {
clearInterval(countdown);
if (typeof playAlarm === "function") {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to check if playAlarm is a function?

window.playAlarm();
}
}
}, 1000);
}

function formatTime(seconds) {
const mins = String(Math.floor(seconds / 60)).padStart(2, "0");
const secs = String(seconds % 60).padStart(2, "0");
return `${mins}:${secs}`;
}

// 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
Loading