Buttons?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Buttons??

I was messing about with a friend and trying to create a simple clicker game. However it didn't work. When we clicked the button, the button would disappear. Here is the code: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <button onclick="myFunction()">Enter</button> <script> var a = 0; document.write(a); function myFunction(){ a = a + 1; document.write(a); } </script> </body> </html> Thanks to anyone who helps!

18th Dec 2017, 8:15 PM
Zakariya
Zakariya - avatar
8 Answers
+ 4
Hello! Here new code the game clicker ↓↓↓ <button onclick="Func()"> click </button> <p id="main"> 0 </p> <script> var count = 0; function Func() { document.getElementById('main').innerHTML = ++count; } </script>
18th Dec 2017, 8:24 PM
James16
James16 - avatar
+ 3
You can do this as follows ↓↓↓ :) <button onclick="Func()"> click </button> <p id="main"> 0s</p> <script> var count = 0; function Func() { document.getElementById('main').innerHTML = ++count + "s"; } </script>
18th Dec 2017, 8:33 PM
James16
James16 - avatar
+ 3
<button onclick="Func()"> click </button> <p id="main"> 0s</p> <script> var count = 0; function Func() { document.getElementById('main').innerHTML = ++count + "s"; count = ++count / 1; } </script> try it ↑↑↑ :)
18th Dec 2017, 8:38 PM
James16
James16 - avatar
+ 2
Thanks!!
18th Dec 2017, 8:25 PM
Zakariya
Zakariya - avatar
+ 1
Sorry about this, but if I wanted to increase the amount the number would go up in e.g 2s how would I do that?
18th Dec 2017, 8:29 PM
Zakariya
Zakariya - avatar
+ 1
ok thanks again
18th Dec 2017, 8:33 PM
Zakariya
Zakariya - avatar
+ 1
I wrote the question wrong. I mean whenever I click the button ot will display 2 then 4 then 6 etc
18th Dec 2017, 8:34 PM
Zakariya
Zakariya - avatar
+ 1
ok sorry about the hassle. thanks
18th Dec 2017, 8:38 PM
Zakariya
Zakariya - avatar