Skip to content
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

WM4 | FATIMA_SAFANA | MODULE-DATA-GROUPS | WEEK3 | ALARMCLOCK #270

Open
wants to merge 2 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
File renamed without changes.
45 changes: 45 additions & 0 deletions Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
//step 1; Access time input $ set alarm button??
const timeInput = document.querySelector("#alarmSet");
const setAlarmButton = document.querySelector("#set");
const remainingTimeCounter = document.querySelector("#timeRemaining");



//step 2; create an event listener when set button is clicked.
setAlarmButton.addEventListener("click", function(){
//console.log(timeInputValue, "<--- the value of input");
let timeInputValue = timeInput.value;
countdown(timeInputValue);
});

//the countdown, how can I set a countdown?
function countdown(timeInputValue) {
let counter = timeInputValue;

// Set up the interval
const intervalId = setInterval(() => {
remainingTimeCounter.innerText = `Time Remaining: ${formatTime(counter)}`;
counter--; // Decrease the counter by 1 and update display of count

// Stop the timer when it reaches below zero
if (counter === 0) {
clearInterval(intervalId); // play alarm
remainingTimeCounter.innerText = "Time Remaining: 00:00"
playAlarm()

}
}, 1000); // Run every 1000 milliseconds (1 second)
}

function formatTime(seconds) {
const minutes = Math.floor(seconds / 60); // Calculate the number of minutes
const remainingSeconds = seconds % 60; // Get the remaining seconds

// Pad minutes and seconds with leading zero if needed
const formattedMinutes = String(minutes).padStart(2, "0");
const formattedSeconds = String(remainingSeconds).padStart(2, "0");

return `${formattedMinutes}:${formattedSeconds}`;
}


function setAlarm() {}

// DO NOT EDIT BELOW HERE
Expand Down
Loading