This commit is contained in:
Ilya Kantor 2019-03-07 10:35:58 +03:00
parent 16cfa3037b
commit cdc1693443
7 changed files with 43 additions and 63 deletions

View file

@ -1,9 +1,9 @@
class Clock {
constructor({ template }) {
this._template = template;
this.template = template;
}
_render() {
render() {
let date = new Date();
let hours = date.getHours();
@ -15,7 +15,7 @@ class Clock {
let secs = date.getSeconds();
if (secs < 10) secs = '0' + secs;
let output = this._template
let output = this.template
.replace('h', hours)
.replace('m', mins)
.replace('s', secs);
@ -24,11 +24,11 @@ class Clock {
}
stop() {
clearInterval(this._timer);
clearInterval(this.timer);
}
start() {
this._render();
this._timer = setInterval(() => this._render(), 1000);
this.render();
this.timer = setInterval(() => this.render(), 1000);
}
}

View file

@ -1,34 +1,21 @@
<!DOCTYPE HTML>
<html>
<script src="clock.js"></script>
<script>
let clock = new Clock({
template: 'h:m:s'
});
clock.start();
<head>
<title>Console clock</title>
</head>
<body>
/* Your class should work like this: */
<!-- source clock -->
<script src="clock.js"></script>
<script>
let clock = new Clock({
template: 'h:m:s'
/*
let lowResolutionClock = new ExtendedClock({
template: 'h:m:s',
precision: 10000
});
clock.start();
/* Your class should work like this: */
/*
let lowResolutionClock = new ExtendedClock({
template: 'h:m:s',
precision: 10000
});
lowResolutionClock.start();
*/
</script>
</body>
</html>
lowResolutionClock.start();
*/
</script>