Countdown Timer
<div id="app"></div>
<script>
var Rue = function (selector, options) {
this.elem = document.querySelector(selector);
this.data = options.data;
this.template = options.template;
};
Rue.prototype.render = function () {
this.elem.innerHTML = this.template(this.data);
}
var app = new Rue('#app', {
data: {
count: 60,
},
template: function (props) {
var html = `${props.count}`;
return html;
}
})
app.render();
var startCount = function() {
var countDown = window.setInterval(function () {
app.data.count--;
if (app.data.count === 0) {
window.clearInterval(countDown);
app.data.count = `End <button id="restart">Restart</button>`;
};
app.render();
}, 1000);
};
startCount();
document.addEventListener('click', function (event) {
let restart = document.querySelector('#restart');
if (event.target != restart) {
return
}
app.data.count = 60;
app.render();
startCount();
})
</script>