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
32 changes: 31 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
function setAlarm() {}
let timer;
function formatTime(totalSeconds) {
let minutes = Math.floor(totalSeconds / 60);
let seconds = totalSeconds % 60;
return (
String(minutes).padStart(2, "0") + ":" + String(seconds).padStart(2, "0")
);
}
function setAlarm() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What happens to the empty setAlarm declaration at the top now that this second declaration has been added?

To "like" or "dislike" this comment, please follow this link

clearInterval(timer);
let seconds = Number(document.getElementById("alarmSet").value);
const title = document.getElementById("timeRemaining");

if (!(seconds > 0)) {
title.innerText = "Time Remaining: 00:00";
return;
}

title.innerText = "Time Remaining: " + formatTime(seconds);

timer = setInterval(() => {
seconds = seconds - 1;
title.innerText = "Time Remaining: " + formatTime(seconds);

if (seconds <= 0) {
clearInterval(timer);
playAlarm();
}
}, 1000);
}

// DO NOT EDIT BELOW HERE

var audio = new Audio("alarmsound.mp3");
let audio = new Audio("alarmsound.mp3");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

How does changing this declaration fit with the DO NOT EDIT BELOW HERE boundary immediately above it?

To "like" or "dislike" this comment, please follow this link


function setup() {
document.getElementById("set").addEventListener("click", () => {
Expand Down
4 changes: 2 additions & 2 deletions Sprint-3/alarmclock/index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<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