-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
135 lines (108 loc) · 3.27 KB
/
index.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/// <reference path="./node_modules/@types/p5/lib/addons/p5.sound.d.ts" />
/// <reference path="./node_modules/@types/p5/global.d.ts" />
/// <reference path="./node_modules/@types/p5/literals.d.ts" />
/// <reference path="./node_modules/@types/p5/constants.d.ts" />
//timer code is from JamieMcGibbon/TechnicalCafe
let seconds = 0;
let minutes = 0;
let hours = 0;
//Define vars to hold "display" value
let displaySeconds = 0;
let displayMinutes = 0;
let displayHours = 0;
//Define var to hold setInterval() function
let interval = null;
//Define var to hold stopwatch status
let status = "stopped";
//Stopwatch function (logic to determine when to increment next value, etc.)
function stopWatch() {
seconds++;
//Logic to determine when to increment next value
if (seconds / 60 === 1) {
seconds = 0;
minutes++;
if (minutes / 60 === 1) {
minutes = 0;
hours++;
}
}
//If seconds/minutes/hours are only one digit, add a leading 0 to the value
if (seconds < 10) {
displaySeconds = "0" + seconds.toString();
} else {
displaySeconds = seconds;
}
if (minutes < 10) {
displayMinutes = "0" + minutes.toString();
} else {
displayMinutes = minutes;
}
if (hours < 10) {
displayHours = "0" + hours.toString();
} else {
displayHours = hours;
}
//Display updated time values to user
document.getElementById("display").innerHTML =
displayHours + ":" + displayMinutes + ":" + displaySeconds;
}
function startStop() {
if (status === "stopped") {
//Start the stopwatch (by calling the setInterval() function)
interval = window.setInterval(stopWatch, 1000);
document.getElementById("startStop").innerHTML = "Stop";
status = "started";
} else {
window.clearInterval(interval);
document.getElementById("startStop").innerHTML = "Start";
status = "stopped";
}
}
//Function to reset the stopwatch
function reset() {
window.clearInterval(interval);
seconds = 0;
minutes = 0;
hours = 0;
document.getElementById("display").innerHTML = "00:00:00";
document.getElementById("startStop").innerHTML = "Start";
}
function oneclick() {
document.getElementById("one").hidden =
!document.getElementById("one").hidden;
}
function twoclick() {
document.getElementById("two").hidden =
!document.getElementById("two").hidden;
}
function threeclick() {
document.getElementById("three").hidden =
!document.getElementById("three").hidden;
}
function fourclick() {
document.getElementById("four").hidden =
!document.getElementById("four").hidden;
}
function fiveclick() {
document.getElementById("ive").hidden =
!document.getElementById("five").hidden;
}
function aclick() {
document.getElementById("ac").hidden = !document.getElementById("ac").hidden;
}
function jclick() {
document.getElementById("cj").hidden = !document.getElementById("cj").hidden;
}
function aboutclick() {
document.getElementById("about").hidden =
!document.getElementById("about").hidden;
}
function load() {
document.getElementById("one").hidden = true;
document.getElementById("two").hidden = true;
document.getElementById("three").hidden = true;
document.getElementById("four").hidden = true;
document.getElementById("about").hidden = true;
document.getElementById("cj").hidden = true;
startStop();
}