-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (45 loc) · 1.61 KB
/
Copy pathindex.js
File metadata and controls
57 lines (45 loc) · 1.61 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
function Machine() {
this._enable = false
this.enable = function () {
this._enable = true
return "Включено"
}
this.disable = function () {
this._enable = false
return "Включено"
}
}
function Timer() {
Machine.call(this)
this.time = 0
this.countdown = function () {
var self = this
var coundown = setInterval(function () {
console.log(self.time)
self.time = self.time - 1
if(self.time === 0) clearInterval(coundown)
}, 1000)
}
this.alerting = function () {
var self = this
var alerting = setInterval(function () {
if(self.time === 0){
console.log("Время вышло")
clearInterval(alerting)
}
else {
console.log("У вас осталось " + self.time + " секунд")
}
}, 3000)
}
this.run = function (time) {
this.time = time
if(!time) return "Задайте начальное значение"
if(this._enable) {
this.countdown()
this.alerting()
return "Timer start"
}
return "Включите таймер"
}
}