I have tried everything, I can't do it!!! Here's my code please help:
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="favicon.ico"/>
<title>Doughtnut Box !</title>
<!--Design-->
<style>
</style>
<!--jQuery and Javascript-->
<script>
var doughnut = 0;
window.setInterval(
doughnut + 1
,1000);
document.getElementById("doughnuts").innerHTML="You have " + doughnut >+ " doughnuts!";
</script>
</head>
<body>
<h3 id="doughnuts"></h3>
</body></html>
Thanks for the code, it was really great! Now how can I save it so that it won't start over when I refresh?
Put them in a function. Also, change your expression to an assignment.
<script>
var doughnut = 0;
window.setInterval(
function () {
doughnut = doughnut + 1;
document.getElementById("doughnuts").innerHTML = "You have " + doughnut + " doughnuts!";
}, 1000);
</script>
Runnable demo below:
var doughnut = 0;
window.setInterval(function () {
doughnut = doughnut + 1;
document.getElementById("doughnuts").innerHTML = "You have " + doughnut + " doughnuts!";
}, 1000);
<div id="doughnuts"></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With