Clicker Game In HTML!
Zexogon (641)

I tried this a few times but now i finally have the hang of javascript (kinda) ill be updating this and add new things/make it look better for now enjoy! :3

-Dart

You are viewing a single comment. View All
MrEconomical (1431)

nice game! its pretty good

some critiques for your javascript (sorry if I sound very critical)
1. += and -= instead of e = e + buttonvalue - its shorter and actually more efficient performance-wise too
2. you should try to use let for defining variables that can change in the future and const for variables that will not - its just a good practice and also looks cool
3. try to use else if instead of sticking a bunch of ifs together, its more efficient and also a good practice
4. use innerText instead of innerHTML - innerHTML makes your sites vulnerable to xss (if somebody inserts malicious scripts and your program puts then directly into the html), innerText interpretes everything as text
5. don't put semicolons - javascript has ASI (automatic semicolon insertion) that will automatically do them for you. I think it looks cleaner, and if I forgot a semicolon somewhere and I never find the missing semicolon, I could never live with myself lol
6. use template literals when "adding" strings together - instead of doing "a" + x you can do `a${x}` I think it looks cleaner

I hope these tips help you improve, and good luck to your future javascript endeavors!

syc1 (20)

@MrEconomical It's a better habit to add semicolons, it helps if you end up trying other languages like Java, C, C++, etc. Of course, it's not my choice, but I'm just stating a point. Other than that I agree with what you said.

MrEconomical (1431)

@syc1 I use c++ and am aware I just don't think its good for js

SilentShadowBla (87)

@MrEconomical Please help me my friend challenged me to make a clicker game with html/js/css and i need help. How do you make a clicks per sec. like how do you make the "cash" automatically go up?
THX in advance :) Btw love your work!

syc1 (20)

@SilentShadowBla Use setInterval(function, ms) to change a localstorage value, then when you display balance, show that localStorage value.

Zavexeon (931)

@MrEconomical Don't forget to mention the scope differences between var and let. var is global, let isn't.

Zexogon (641)

@MrEconomical thanks for the info (especially else if because I couldn’t figure that out :facepalm:) and I will be changing inner html and with the adding functions I’m still used to python and stuff so I just went with that but I will be improving and I love the criticism thanks for the feedback!

mwilki7 (787)

@MrEconomical
I haven't seen any performance bonuses using var1+=var2 vs var1 = var1 + var2
The compiler should be smart enought to detect that.

MrEconomical (1431)

@mwilki7 it actually does make a performance difference with strings
because a += b adds whatever value to the location of the variable a in memory, while a = a + b creates a + b in memory then assigns that to a
it probably won't make much of a difference in js tbh

mwilki7 (787)

@MrEconomical
performance results im getting are not describing a difference

MrEconomical (1431)

@mwilki7 one of my programs ran twice as fast using += rather than a = a + b

in c++

mwilki7 (787)

Would have to look at the program

RohilPatel (388)

Check out my "Grades Clicker". You will have some reference there. @SilentShadowBla

Zexogon (641)

@RohilPatel is this advertising nah jk your game is pretty good I saw it I wish I had dem css skills

RohilPatel (388)

Yea! I wouldn't have a problem teaching you. Sorry if I gave u the impression that I was advertising... @Zexogon