-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
65 lines (52 loc) · 1.88 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Required variables
var session_seconds = "00";
var session_minutes = 25;
// Audio files
var click_sound = new Audio("click.mp3");
var bell = new Audio("bell.mp3");
// Starting template for the timer
function template() {
document.getElementById("minutes").innerHTML = session_minutes;
document.getElementById("seconds").innerHTML = session_seconds;
}
function start_timer() {
click_sound.play();
// Change the minutes and seconds to starting time
session_minutes = 24;
session_seconds = 59;
// Add the seconds and minutes to the page
document.getElementById("minutes").innerHTML = session_minutes;
document.getElementById("seconds").innerHTML = session_seconds;
// Start the countdown
var minutes_interval = setInterval(minutesTimer, 60000);
var seconds_interval = setInterval(secondsTimer, 1000);
// Functions
// Function for minute counter
function minutesTimer() {
session_minutes = session_minutes - 1;
document.getElementById("minutes").innerHTML = session_minutes;
}
// Function for second counter
function secondsTimer() {
session_seconds = session_seconds - 1;
document.getElementById("seconds").innerHTML = session_seconds;
// Check if the seconds and minutes counter has reached 0
// If reached 0 then end the session
if (session_seconds <= 0) {
if (session_minutes <= 0) {
// Clears the interval i.e. stops the counter
clearInterval(minutes_interval);
clearInterval(seconds_interval);
// Add the message to the html
document.getElementById("done").innerHTML =
"Session Completed!! Take a Break";
// Make the html message div visible
document.getElementById("done").classList.add("show_message");
// PLay the bell sound to tell the end of session
bell.play();
}
// Reset the session seconds to 60
session_seconds = 60;
}
}
}