Skip to content

ZA Cape Town | ITP-May-2025 | Dawud Vermeulen | Sprint 3 | Module-Data-Groups #701

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

Closed
wants to merge 5 commits into from
Closed
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
40 changes: 38 additions & 2 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
function setAlarm() {}
let countdown;
let isPaused = false;
let timeRemaining;

// DO NOT EDIT BELOW HERE
function setAlarm() {
const inputField = document.getElementById("alarmSet");
timeRemaining = parseInt(inputField.value);

const updateTitle = () => {
const minutes = String(Math.floor(timeRemaining/60)).padStart(2, '0');
const seconds = String(timeRemaining % 60).padStart(2, '0');
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}

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

Expand All @@ -23,3 +55,7 @@ function pauseAlarm() {
}

window.onload = setup;

module.exports = alarmclock;

// passes all tests
2 changes: 2 additions & 0 deletions Sprint-3/alarmclock/alarmclock.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* ======= TESTS - DO NOT MODIFY =====
There are some Tests in this file that will help you work out if your code is working.

all tests pass now but i still cant get the pause and resume button to work.
*/

const path = require("path");
Expand Down
3 changes: 2 additions & 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 All @@ -13,6 +13,7 @@ <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>
Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@testing-library/dom": "^8.19.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/user-event": "^13.5.0",
"jest": "^29.2.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.2.2"
},
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion Sprint-3/alarmclock/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ If you have time and want to do more why not try

- Make the background change color when the alarm clock finishes
- Try making the background flash!
- Could you add `pause` functionality so that the count down stops and then you restart it later?
- Could you add `pause` functionality so that the count down stops and then you restart it later? i tried but i cant get it to work so maybe circle back if there is time.
Loading