Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialilithya
19,818 PointsEvaluate this jQuery code, if you feel like it.
Attached you'll find a link to a tiny fun questionnaire I built, in order to train the latest JavaScript skills I've learned here.
Everything works the way I wanted, but I'd like to hear what do you think of my jQuery code? Is it a bit modular? Am I'm still writing too complex code?
If you have anything to say, your feedback and critique will help me to improve my JavaScript skills.
http://codepen.io/ilithya/pen/EaMWde
Thanks :)
Simon Sørensen
17,304 PointsThat's very nice.
ilithya
19,818 PointsSimon Sørensen Thanks for stopping by and looking at my tiny app. Happy coding :)
Simon Sørensen
17,304 PointsYou too, thank you :D
1 Answer
eck
43,038 PointsThat was cute :P I like you input styling!
So, this little app is not really at a size where it can be thought of as modular, but there is one obvious tip that I have for you from seeing your code. I have been reading a very helpful book on how to write clean code and one of the ideas is that functions should be small and focused on perform one task. Your "revise" function is very long, and glancing at it, it is hard to quickly get an understanding of what is taking place.
If you did build a larger application and wanted this to be modular component of it, you should look into object oriented JavaScript programming patterns.
Those are two really good directions to take your learning in if you hope to master JS, I hope you find them helpful! ♥
ilithya
19,818 PointsHi Erik Krieg,
Thank you so much for your fast answer! This is exactly the kind of feedback I was looking for.
In fact with the long function, I first had it as 3 different functions, but thought I was repeating myself. And this is exactly what I want to improve: the mindset of writing less complex and unreadable code, and transform it into modular and easy to read. At this point, I still had no idea how modular my code has became, after the courses I've taken here so far, so your words are a big help.
I'll take your kindly advice, and try to get my hands into that book to write clean code. I really want to improve as much as I can my JS code, as until now I still find it hard to set up my mind into that less complex writing style I have. Hopefully I'll get there.
I'll try refactoring this tiny app in the next few days after some of this read and will do a bit more JS courses here.
Happy coding :)
ilithya
19,818 PointsIt's me again Erik Krieg... not that you probably care anymore, but I already refactored that codepen, thanks to your feedback. I also added comments, which I remembered I lacked to include.
I'll give it a try later in the week anyway, and see if I can refactor this code even more for the best.
eck
43,038 PointsSure I care! Your changes have definitely improved readability, but there is more that can be done. Right now you have functions that validate AND update messaging. Your code can be even more readable and flexible if you take it a little further by breaking those into separate functions :D
ilithya
19,818 PointsHey Erik Krieg, I got the book! I'll let you know how I feel after reading it and refactoring that code here.
It turned out that a few colleagues and friends developers knew about this book and told me is like a bible for programers. Looking forward for this read. Thanks for the tip!
eck
43,038 PointsThat's great! :D
Yes, a lot of people consider this book to be a great authority on writing comprehensive code. Specifically, the first several chapters are a great resource for developer using any object oriented programming language. I have not completely finished the book yet, but I hear that towards the end the book might become more Java-specific. Regardless, the content in this book it super helpful.
♥
ilithya
19,818 Pointsilithya
19,818 PointsBy the way, I just noticed that somehow Safari was buggy when I used the method .html(). I changed it to .text() and now it's working better.
Any ideas why .html() is buggy only in Safari?