Skip to content

ZA Cape Town | ITP-May-2025 | Dawud Vermeulen | Sprint 3 | Alarm-Clock #737

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
38 changes: 37 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
function setAlarm() {}
let countdown; // just to make it avails for later
let isPaused = false; // start off false so the timer is not paused
let timeRemaining; // time remaining in seconds

function setAlarm() {
const inputField = document.getElementById("alarmSet"); //get input
timeRemaining = parseInt(inputField.value); //set time remaining in seconds

const updateTitle = () => {
const minutes = String(Math.floor(timeRemaining/60)).padStart(2, '0'); // minutes
const seconds = String(timeRemaining % 60).padStart(2, '0'); // seconds
document.getElementById("timeRemaining").innerText = `Time Remaining: ${minutes}:${seconds}`;
};

updateTitle();

countdown = setInterval(() => {
if (!isPaused){
timeRemaining = timeRemaining - 1;
updateTitle();

if (timeRemaining <= 0) {
clearInterval(countdown);
playAlarm();
}
}
}, 1000);
}

function pauseTimer() {
isPaused = !isPaused;
document.getElementById("pause").innerText = isPaused ? "Resume Timer" : "Pause Timer";
}

// DO NOT EDIT BELOW HERE

Expand All @@ -12,6 +44,10 @@ function setup() {
document.getElementById("stop").addEventListener("click", () => {
pauseAlarm();
});

document.getElementById("pause").addEventListener("click", () => {
pauseTimer();
});
}

function playAlarm() {
Expand Down
5 changes: 3 additions & 2 deletions 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 All @@ -13,8 +13,9 @@ <h1 id="timeRemaining">Time Remaining: 00:00</h1>
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="pause" type="button">Pause Timer</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
</body>
</html>
</html>