-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathchronometer.js
More file actions
60 lines (50 loc) · 1.2 KB
/
chronometer.js
File metadata and controls
60 lines (50 loc) · 1.2 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
53
54
55
56
57
58
59
60
class Chronometer {
constructor() {
// ... your code goes here
this.currentTime= 0;
this.intervalId= null;
}
start(callback) {
this.intervalId= setInterval(()=> {
this.currentTime= this.currentTime+1 ;
}, 1000);
callback(this.intervalId)
}
getMinutes() {
// ... your code goes here
const minutes= Math.floor (this.currentTime/60);
return minutes
}
getSeconds() {
// ... your code goes here
const seconds= Math.floor(this.currentTime%60);
return seconds
}
computeTwoDigitNumber(value) {
let twoDigits = value.toString();
if (value.length < 2) {
numStr = '0' + numStr;
}
return twoDigits;
// ... your code goes here
}
stop() {
// ... your code goes here
clearInterval(this.intervalId);
this.intervalId= null;
}
reset() {
// ... your code goes here
this.currentTime=0
}
split() {
let split= (this.getMinutes()) + ":"+ (this.getSeconds())
// ... your code goes here
return split
}
}
// The following is required to make unit tests work.
/* Environment setup. Do not modify the below code. */
if (typeof module !== 'undefined') {
module.exports = Chronometer;
}