+ 1

Javascript DOM

i wanna make an alert button when you keep clicked it, the number increas. ex: first alert : "You clicked 1 time" second alert : "You clicked 2 times" third alert:"You clicked 3 times" and so on sorry for my poor english, i hope you can understand me

5th Sep 2020, 4:46 AM
Azra Fadil
Azra Fadil - avatar
5 Réponses
+ 3
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button>click</button> <script> let count = 1; let btn = document.querySelector("button") btn.addEventListener("click",()=>{ alert(`You click ${count}`) count++; }) </script> </body> </html>
5th Sep 2020, 5:26 AM
Akash Agrawal
Akash Agrawal - avatar
5th Sep 2020, 5:09 AM
WenHao1223
WenHao1223 - avatar
+ 2
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button onclick="ClickMe()">ClickMe</button> </body> </html> var count1 = 1; var count2 = 1; function ClickMe(){ if(count1 == count2 ){ alert(count2); count1++; count2 = 0; } count2++; }
5th Sep 2020, 5:13 AM
Muhammadamin
Muhammadamin - avatar
+ 2
idea thief Try this
5th Sep 2020, 5:13 AM
Muhammadamin
Muhammadamin - avatar
0
...can you guys kindly explain to me from line to line please
30th Oct 2020, 7:58 PM
Atsu Fenuku
Atsu Fenuku - avatar