0
I coded a counter which start from 0. How can I place a value for the counting to stop at 20.
<!DOCTYPE html> <html> <head> <title>Counter</title> </head> <body> <h1 id="count">0</h1> <button onclick="Hi()">Click me</button> <script> let count=0; function Hi(){ count++; document.getElementById("count").innerHTML=count; } </script> </body> </html>
3 Answers
+ 4
Post you code also we can check easily.
+ 4
Where you write function Hi() inside body you can write
if(count==20)
break;
and use loop
+ 2
You could check before incrementing it.
if(count <20) {
count++;
}