-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclicky.js
More file actions
45 lines (39 loc) · 1.08 KB
/
clicky.js
File metadata and controls
45 lines (39 loc) · 1.08 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
//todo
$(document).ready(function() {
var num = 0;
$('#clickThis').click(function() {
if(num < 1){
var time = 6, //in seconds
display = $('#time'),
button = $('#startAndStop');
var status = startTimer(time, display, button, num);
}
num += 1;
$('#number').html(function(i, val) {
return +val+1
});
})
});
//TIMER
function startTimer(duration, display, button, num) {
var timer = duration, minutes, seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
if(seconds == 01){
display.text("TIME UP!");
button.text("PLAY AGAIN!");
timer.stop();
num = 0;
return 1
}
else{
display.text("You have " + minutes + ":" + seconds + " seconds!");
}
if (--timer < 0) {
timer = duration;
}
}, 1000);
}