I have a value var x = "2"
. How can I increment x each second so that one second from when I defined x, x will equal to 3?
My code is shown bellow:
<img src="cookie.jpg" style="text-align:center; width:250px;" id="cookie" onclick="Click()">
<h1 id="score">0</h1>
<script>
var cookie = document.getElementById("cookie");
function Click() {
var scoreStr = document.getElementById("score");
var score = parseInt(scoreStr.textContent);
score ++;
scoreStr.textContent = score;
}
</script>
Use a setInterval and set it to one second =>
1000