0% found this document useful (0 votes)
8 views7 pages

Countdown Timer for Coach Confirmation

Uploaded by

Hamada Mansour
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Countdown Timer for Coach Confirmation

Uploaded by

Hamada Mansour
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

<center>

<h1>
<span id="m"></span>
<span>:</span>
<span id="s"></span>
‫الوقت المتبقي للتأكيد من قبل المدرب‬
</h1>
<br>
</center>
<script>
var s=60;
var m=4;
var time= setInterval(function() {timer()}, 1000);
function timer(){
s--;
if(s==-1){
m--;
s=59;
if(m==-1){
m=0;
s=0;
clearInterval(time);
alert("‫;)"انتهى الوقت المحدد للتأكيد‬
}
}
[Link]("m").innerHTML = m;
[Link]("s").innerHTML = s;
}
</script>

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Countdown Timer</title>

<style>

body {

display: flex;

justify-content: center;

align-items: center;

height: 100vh;

margin: 0;

font-family: Arial, sans-serif;

background-color: #e0f7fa;

#container {

text-align: center;

background: white;

padding: 20px;

border-radius: 10px;

box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

h1 {

font-size: 2.5em;

color: #00796b;

margin: 0;

#timer {

display: flex;

justify-content: center;

align-items: baseline;
font-size: 4em;

font-weight: bold;

color: #004d40;

span {

margin: 0 5px;

#controls {

margin-top: 20px;

button {

font-size: 1em;

padding: 10px 20px;

margin: 5px;

border: none;

border-radius: 5px;

cursor: pointer;

background-color: #004d40;

color: white;

transition: background-color 0.3s;

button:hover {

background-color: #00332e;

#notification {

margin-top: 20px;

font-size: 1.2em;

color: #d32f2f;
}

#timeInput {

font-size: 1em;

padding: 10px;

margin: 10px;

border: 1px solid #00796b;

border-radius: 5px;

</style>

</head>

<body>

<div id="container">

<h1>‫< الوقت المتبقي‬/h1>

<div id="timer">

<span id="m">04</span>

<span>:</span>

<span id="s">00</span>

</div>

<div id="controls">

<input type="number" id="timeInput" placeholder="‫ "أدخل الوقت بالثواني‬min="1">

<button id="start">Start Timer</button>

<button id="stop">Stop Timer</button>

<button id="reset">Reset Timer</button>

</div>

<div id="notification"></div>

</div>

<script>
let s = 0; // ‫الثواني‬

let m = 0; // ‫الدقائق‬

let timerInterval;

const timeInput = [Link]("timeInput");

function formatTime(seconds) {

const minutes = [Link](seconds / 60);

const secs = seconds % 60;

return {

minutes: [Link]().padStart(2, '0'),

seconds: [Link]().padStart(2, '0')

};

function updateTimerDisplay() {

const { minutes, seconds } = formatTime(m * 60 + s);

[Link]("m").innerText = minutes;

[Link]("s").innerText = seconds;

function startTimer() {

clearInterval(timerInterval); // Ensure no multiple intervals are running

const totalSeconds = parseInt([Link], 10);

if (isNaN(totalSeconds) || totalSeconds <= 0) {

alert("Please enter a valid time in seconds.");

return;

s = totalSeconds % 60;
m = [Link](totalSeconds / 60);

updateTimerDisplay();

timerInterval = setInterval(() => {

if (s === 0 && m === 0) {

clearInterval(timerInterval);

[Link]("notification").innerText = "‫;"انتهى الوقت المحدد للتأكيد‬

[Link]("notification").[Link]("alert");

playAlertSound();

return;

if (s === 0) {

m--;

s = 59;

} else {

s--;

updateTimerDisplay();

}, 1000);

[Link]("notification").innerText = "";

[Link]("notification").[Link]("alert");

function stopTimer() {

clearInterval(timerInterval);

function resetTimer() {

clearInterval(timerInterval);
m = 0;

s = 0;

updateTimerDisplay();

[Link]("notification").innerText = "";

function playAlertSound() {

const audio = new Audio('alert.mp3'); // Make sure you have an alert sound file in the same directory

[Link]();

[Link]("start").addEventListener("click", startTimer);

[Link]("stop").addEventListener("click", stopTimer);

[Link]("reset").addEventListener("click", resetTimer);

// Initialize display

updateTimerDisplay();

</script>

</body>

</html>

Common questions

Powered by AI

Upon completion, the timer uses a visual text notification in the interface and plays an audio alert. The text notification modifies the DOM to provide visual feedback, while the audio alert serves as an auditory cue, ensuring that users are effectively informed when the countdown ends. These methods enhance user awareness and response .

The script uses a combination of event listeners and interval management to handle concurrent operations. Each button triggers specific functions: starting initiates the countdown with a single interval, stopping clears the interval to pause time decrement, and resetting clears the interval and sets time to zero. This separation and clearing mechanism ensures that only the desired timer action occurs at any given time, mitigating concurrency issues .

The application uses DOM manipulation techniques in the 'updateTimerDisplay' function, which executes every second. It retrieves the current timer values, formats them, and updates the HTML elements representing the minutes and seconds. This ensures that as time decrements, the displayed time always reflects the current countdown state without delay or inaccuracies .

Resetting the notification message at the start ensures any prior alert states are cleared before a new countdown begins. This avoids confusion, maintaining a predictable interface condition that reflects current operations. It is significant in preserving clarity as ongoing or new tasks commence without residual messages or alerts from previous actions interfering with current user interactions .

Inline styles in the timer application, such as margins and background colors, visually organize and enhance the user interface, contributing to a clean, centered layout. JavaScript functions handle the dynamic functionality of the timer, for instance, updating the countdown display, starting/stopping the interval, and triggering notifications. The interplay between styles and scripts provides both an aesthetically pleasing and functional application interface .

The timer's design utilizes a color scheme of tranquil blues and greens, promoting a calm user experience. The structured layout centers content and enhances focus, while shadows and borders provide depth, creating a visually distinct interactive area. These choices reflect principles of clarity, emphasis, and user engagement, aligning aesthetics with functional guidance .

The timer handles user input through a numeric input field where users specify time in seconds. It validates this input by checking if the value is a valid integer and greater than zero. If the condition isn't met, it alerts the user to enter a valid time. This validation prevents incorrect or unintended timer operations, ensuring robust functionality and preventing errors related to invalid time entries .

In the countdown timer script, the process begins with an interval function set to decrease seconds ('s') every second. If 's' reaches -1, indicating the end of a minute, it checks for 'm' (minutes). If 'm' is zero, the timer stops, as both minutes and seconds are at their minimum. If 'm' is not zero, a minute is decremented from 'm', and 's' is reset to 59 seconds. This ensures a smooth transition from one minute to the next .

The script uses a helper function 'formatTime' which computes minutes by dividing total seconds by 60 and determining remaining seconds using modulo 60. It converts these values to strings and pads them with leading zeros for single-digit values to maintain a consistent two-digit format in the display. This method ensures that the countdown is clearly presented, adhering to the 'MM:SS' format .

Clearing the interval in the timer's start and reset functions prevents the creation of multiple overlapping intervals. When a new cycle begins or the timer resets, clearing ensures only a single interval is active, thus preventing possible timing conflicts or unintended behaviors such as multiple alerts or incorrect time display .

You might also like