So here is my code and I want to add 1 to total every second`
var doughnut = 0;
function myFunction(){
document.getElementById("total").innerHTML = " total: " + setInterval(doughnut +1, 1000) ;
}
setInterval accepts two arguments:
Basically each second (1000 ms) the function increments the doughnut value and writes the updated value to the HTML element with id total
.
Try this:
var doughnut = 0;
setInterval(function () {
doughnut++;
document.getElementById("total").innerHTML = " total: " + doughnut;
}, 1000);