0
I apologize if I’m posting in the wrong place The point is that I’m starting in Javascript and I don’t know why this script doesn’t work.
<body>
<p>Ganhe alguns meticais</p>
<h2 id="cash">0</h2>
<button onclick="jogar();">Jogar</button>
</body>
<script>
function jogar() {
var x = 1;
while (x < 1000) {
document.getElementById('cash').innerHTML = String(x);
x = x + 10;
if (x === 150) {
break ();
}
}
}
</script>
the problem is that
break();
is a command, not a Function, so you need to remove the parentheses:break;
– Ricardo Pontual
Thanks, that’s what it was. But still the script only prints one number, besides updating #cash when the variable x came incrementing. Could give me a light?
– Macucule
your script should run so fast that you can’t notice the values changing
– Ricardo Pontual
Thanks. I’ll figure it out.
– Macucule
You can set a 1 or 2 second wait for each number change x = x + 10;. Can use
setInterval
orsetTimeout()
for that reason.– MauroAlmeida