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>

23rd Sep 2020, 5:04 PM
Ifechukwu Jeremiah
Ifechukwu Jeremiah - avatar
3 Answers
+ 4
Post you code also we can check easily.
23rd Sep 2020, 5:06 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 4
Where you write function Hi() inside body you can write if(count==20) break; and use loop
23rd Sep 2020, 5:19 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
You could check before incrementing it. if(count <20) { count++; }
23rd Sep 2020, 5:14 PM
Shri Hari L
Shri Hari L - avatar