a/20966212/1636522

by wared

HTML

<div id="money"></div>
<a href="#">replay</a>

CSS

body{font-family:Arial}
div{font:normal 64px "Arial Black"}

JavaScript

var money = 5,
    ceiling = 10,
    el = document.getElementById('money'),
    tid = setInterval(update, 500);

function update() {
    refresh(++money);
    if (money === ceiling) clearInterval(tid);
}

function refresh(value) {
    el.innerHTML = value + '$';
}

refresh(money);

document.getElementsByTagName('a')[0].onclick = function (e) {
    e.preventDefault();
    tid && clearInterval(tid);
    refresh(money = 5);
    tid = setInterval(update, 500);
};