Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
57 changes: 56 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
function setAlarm() {}
let timerInterval = null;
let remainingSeconds = 0;

// Resets timer state
function resetTimer() {
if (timerInterval !== null) {
clearInterval(timerInterval);
timerInterval = null;
}
Comment thread
cjyuan marked this conversation as resolved.
Outdated
remainingSeconds = 0;
}
Comment thread
cjyuan marked this conversation as resolved.
//Starts the alarm counbtdown
function setAlarm() {
// Read the minutes value from the alarm input field
const minutesInput = document.getElementById("alarmSet");
const seconds = parseInt(minutesInput.value, 10);
// Ignore invalid or non-positive input

if (isNaN(seconds) || seconds <= 0) {
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indentation is off.

Have you installed the prettier VSCode extension and enabled "Format on save/paste" on VSCode,
as recommended in https://github.com/CodeYourFuture/Module-Structuring-and-Testing-Data/blob/main/readme.md ?


If you have enabled "Format on save" but it is not working, it is likely that you haven't assign a formatter for JS file. This could happen if you have zero or multiple extensions that can format .js file.

If you have installed "Prettier" extension. To assign it as the formatter of JS code, you can try:

  1. Use "Format document" to format the JS file. Sometimes, VSCode will ask you to choose a formatter, and you can manually select "Prettier".
  2. Edit settings.json and set Prettier as the default formatter for JS.

See: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you. it seems it wasn't on. i've applied this now.

// Reset any existing timer first
resetTimer();

// Store the input as the remaining seconds to count down
remainingSeconds = seconds;

// Update display immediately
updateTimeDisplay();

// Start countdown
timerInterval = setInterval(() => {
remainingSeconds--;

updateTimeDisplay();

if (remainingSeconds <= 0) {
resetTimer();
updateTimeDisplay();
playAlarm();
}
}, 1000);
}

// Converts remainingSeconds into MM:SS format and updates the display
function updateTimeDisplay() {
const minutes = Math.floor(remainingSeconds / 60);
Comment thread
cjyuan marked this conversation as resolved.
const seconds = remainingSeconds % 60;

const formattedMinutes = minutes.toString().padStart(2, "0");
const formattedSeconds = seconds.toString().padStart(2, "0");

const timeDisplay = document.getElementById("timeRemaining");
timeDisplay.textContent = `Time Remaining: ${formattedMinutes}:${formattedSeconds}`;
}


// DO NOT EDIT BELOW HERE

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