Skip to content

London_ITP_Jan_2025 | Franklin Kamela | Module_Data_Groups | Feature_Quote_Generator #480

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
73 changes: 70 additions & 3 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,83 @@
function setAlarm() {}
const alarmSet = document.querySelector("#alarmSet");
const alarmCount = document.querySelector("#alarmCount");
const pauseBtn = document.querySelector("#pause");
let countdown;
let remainingTime;
let isPaused = false;

function setAlarm(time) {
remainingTime = time;
alarmCount.innerText = convertSeconds(remainingTime);

clearInterval(countdown);
pauseAlarm();

countdown = setInterval(() => {
if (remainingTime <= 0){
playAlarm();
clearInterval(countdown);
}else {
remainingTime -= 1;
alarmCount.innerText = convertSeconds(remainingTime);
}
}, 1000)
alarmSet.value = "";
isPaused = false;
pauseBtn.innerText = "Pause Alarm";
}

function stopAlarm(){
clearInterval(countdown);
alarmCount.innerText = convertSeconds(0);
pauseAlarm();
isPaused = false;
pauseBtn.innerText = "Pause Alarm";
}


function pausingAlarm(){
console.log("Pause button clicked");
if (!isPaused){
clearInterval(countdown);
pauseAlarm();
pauseBtn.innerText = "Resume Alarm";
isPaused = true;
} else {
countdown = setInterval(() => {
if (remainingTime <= 0) {
playAlarm();
clearInterval(countdown);
} else {
remainingTime -= 1;
alarmCount.innerText = convertSeconds(remainingTime);
}
}, 1000);
pauseBtn.innerText = "Pause Alarm";
isPaused = false;
}
}
function convertSeconds(seconds) {
let mm = Math.floor(seconds / 60);
let ss = seconds % 60;
let clockDisplay = `${String(mm).padStart(2, "0")}:${String(ss).padStart(2, "0")}`;
return clockDisplay;
}

// DO NOT EDIT BELOW HERE

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

function setup() {
document.getElementById("set").addEventListener("click", () => {
setAlarm();
setAlarm(alarmSet.value);
});

document.getElementById("stop").addEventListener("click", () => {
pauseAlarm();
stopAlarm();
});

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

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,15 +4,16 @@
<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">
<h1 id="timeRemaining">Time Remaining: 00:00</h1>
<h1 id="timeRemaining">Time Remaining: <span id="alarmCount">00:00</span></h1>
<label for="alarmSet">Set time to:</label>
<input id="alarmSet" type="number" />

<button id="set" type="button">Set Alarm</button>
<button id="pause" type="button">Pause Alarm</button>
<button id="stop" type="button">Stop Alarm</button>
</div>
<script src="alarmclock.js"></script>
Expand Down
Loading