Responsive tip-caluculator-app using SASS, Grid, Flexbox and vanillaJS
Design comparison
Solution retrospective
I think HTML and CSS are preety solid but since it is my first JS written by myself i'm looking for any feedback on the code. Are there any bad practices i should work on ? Any bugs i missed ? Overcomplicated something ? Is it generally readable ?
Community feedback
- @mattstuddertPosted over 3 years ago
Nice work on this challenge; your solution looks great! I'd recommend reviewing the accessibility and HTML report and the try to resolve those issues.
Instead of using
document.getElementsByClassName
anddocument.getElementById
, it's now more common to usedocument.querySelector
and pass in the CSS selector.There's not much need for the initial if statement either. Running the
ready
function when the DOM content is loaded is fine. I'd also avoid usingvar
nowadays and exclusively useconst
orlet
, defaulting toconst
. This will make you much more intentional about how you declare your variables.Overall, you've broken up the functions well. Try looking for repetitive blocks of code that could be refactored and reused.
I hope that helps. Keep up the great work!
Marked as helpful1@Pow3rZPosted over 3 years ago@mattstuddert I resolved issues from the report right away but had some problem with generating new report. For some time it didn't see changes made and gave me the same issues again.
Does querySelector have some advantages over getElement methods other than not being restricted to only class and id ?
From what i understand the initial if statement does just that checks if DOM content is loaded, or waits for it to load. Yeah i guess i have to step up my variables game :)
Thank you for your feedback and have a great day!
0@mattstuddertPosted over 3 years ago@Pow3rZ, sometimes it can take a minute or two for the live version of your project to update. It looks like you've resolved it now! 🎉
Using
querySelector
doesn't necessarily have lots of advantages. It just keeps your code a bit more consistent and provides more flexibility for how you select elements.Yeah, you're right about the if statement, but it's not necessary as the
ready
function will run when the document is loaded anyway. That's the purpose of that event listener. It's not a big deal either way, but it would remove a few lines of unnecessary code 🙂1@Pow3rZPosted over 3 years ago@mattstuddert Thank you for your advice ! I found
querySelector
andquerySelectorAll
much easier to use.querySelector
used on a class returns first instance of that class automatically andquerySelectorAll
returns array not object likegetElementsByClass
so it is easier to manipulate like i.e. you can useforEach
method on it by default. Saves some code and makes it easier to read. Thanks again. Cheers0@mattstuddertPosted over 3 years ago@Pow3rZ, that's great to hear! They definitely make selecting and working with elements in JS much easier! 🚀
0
Please log in to post a comment
Log in with GitHubJoin our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord