Recently I'm making the website which should contain the counter of population. The idea is to add a random number(1-10) every second.
I've come up with the following piece, but it refreshes every time I restart the page.
var population = 150
var random = Math.floor(Math.random() * 10) +1;
var t = setInterval(function() {
population += random;
document.getElementById("pop").innerHTML = population;
}, 1000);
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire