-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatch.js
More file actions
52 lines (43 loc) · 1.06 KB
/
watch.js
File metadata and controls
52 lines (43 loc) · 1.06 KB
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
var seconds = 0;
var minutes = 0;
var interval = null;
var timeWatch = 0;
var control = false;
//called when the page loads to begin the timer
function startTimer(){
//if(!control){
//1000 milliseconds = 1 second
if(interval === null){
//control = true;
interval = setInterval("updateTime()", 1000);
}
}
//called every 1000 milliseconds to update the timer
function updateTime(){
++seconds;
var currentMinutes = "0" + minutes;
var currentSeconds = "0" + seconds;
if(currentSeconds >= 10){
currentSeconds = seconds;
}
if(currentMinutes >= 10){
currentMinutes = minutes;
}
while(seconds === 60){
seconds = 0;
minutes++;
}
timeWatch = currentMinutes + ":" + currentSeconds;
document.getElementById("watch").value = timeWatch;
document.getElementById("watch").innerHTML = timeWatch;
//document.getElementById("vis").innerHTML = $("#soFar").text();
}
function stopTimer(){
var endTime = $("#watch").text();
if(interval !== null){
interval = clearInterval(interval);
interval = null;
}
//$("#watch").text(timeWatch);
//control = false;
}