Hello to all the devs out there! This is my first post. I saw that there are a lot of awesome devs up here so I was wondering.. could you look over my first JavaScript code? It's hardly anything, just something super basic I made with the things I learned. If there is any way that I could improve my code please let me know. And if there is an easier way to do what I did, I am open and willing to learn. Thank you!
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (5)
Hey that's pretty cool! Here's my feedback on the code:
Make the prompt a
const
variable instead oflet
.Please, don't use
var
anymore, you seem to knowlet
andconst
do exist ;)Your prompt is prone to XSS, try to find a different solution for inserting content in the DOM
Don't use
else if
statements, they add unesseccary code, anif
statement is good enough (bail out early)(My opinion) use arrow functions instead of regular ones, ex:
const foo = (a, b) => a + b;
(Also my opinion) use
document.querySelector('.classEl #idEl');
How long have you been using JavaScript? It looks amazing if you're just starting out!
Thank you for such awesome feedback! I will definitely take all this into account. I really appreciate it. I might be hittin you up for more code reviews.
I started learning about 10 days ago. I'm taking courses on Udemy and got a couple books too. And been reading things on javascript.info (they have some nice documentation). Do you know any good Javascript courses or resources for beginners?
Thank you again!
10 days ago? This is some solid code! I'd recommend looking at Traversy Media, Google Chrome Developers, Andre Madarang and Fireship. Once you get more advanced you'll feel home in documentation sites like Mozilla
There is no need to init the text variable on top of the function. Just init it before setting innerHTML
Thank you for your feedback! Taken into account.