DEV Community

Cover image for Finally Understanding JavaScript

Finally Understanding JavaScript

Lynne on August 24, 2020

I can't tell you enough, how much I am starting to get JavaScript after four weeks of tutorials, reading, challenges, and games! This really was a ...
Collapse
 
patricktingen profile image
Patrick Tingen

I think you can do better with the birthday song. Why not use a loop to 4 instead of 2 and use an IF-THEN-ELSE construction to print the different line on the count of 3.....
Apart from that: happy coding :)

Collapse
 
ericgeek profile image
EricGeek

If-then-else? How about picking up another technique, the ternary operator?

while (i < 4) {
let message = (i ==3) ? "Happy Birthday dear " + name + "," : "Happy Birthday to you.
";
document.write(message);
i = i + 1;
}

Which isn't the end of ways to refactor this. You could get rid of the temporary variable by having the ternary inside the document.write(), and you could change the while loop to a for loop. There's almost never only one way to do something when it comes to programming.

Collapse
 
lynnecodes profile image
Lynne

This is great! Thanks for building on this code and showing me another way to write it! I'm learning so much.

Collapse
 
lynnecodes profile image
Lynne

Nice! I didn’t think of that! Thanks so much for pointing that out. That’s great advice and I’ll keep that in mind for improvement. 👍🏼

Collapse
 
psiho profile image
Mirko Vukušić • Edited

That feeling is what you need to be a programmer. I can tell you, after 30 years of programming, it never left me. As long as you follow your passion(s) and are not trapped with job requirements/clients you don't like but are forced to work on. Then its pure work.
That feeling is the most importsnt requirement. After that, you only need time (a fun time!). No degrees, no fancy hardware, no big companies.

Collapse
 
lynnecodes profile image
Lynne

That's exactly what I want! To not feel like I'm doing something that I'm forced to work on but actually enjoy. And I think I found it in programming. What I'm learning is getting very exciting!

Collapse
 
pandaquests profile image
Panda Quests

No one understands JavaScript:
res.cloudinary.com/practicaldev/im...

Collapse
 
lynnecodes profile image
Lynne

Haha. You’re absolutely right!!

Collapse
 
aissshah profile image
aishah

Great work! I was in your position not too long ago. Still learning now.

I am also a visual learner and I really like puzzles. So, I spent a lot of time on Codewars, which helped expose me to loads of different methods. Though, it won't teach you anything about the DOM.

Keep us updated! :)

Collapse
 
lynnecodes profile image
Lynne

I really like puzzles too. I’ll check that out. It’s always great to see one problem many different ways. Thanks for the suggestion!

Collapse
 
lynnecodes profile image
Lynne

I’ll definitely be taking the time to read it! Thank you for sharing your article!

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

I got so excited when I finally understood how loops work

Sounds more like understanding programming in general than just understanding javascript. Good luck with your learning :D

Collapse
 
lynnecodes profile image
Lynne

It just felt like figuring one thing out was a gateway to understanding all that’s programming. Haha. What a rush! Thanks for the luck! My brain appreciates it!

Collapse
 
bias profile image
Tobias Nickel

I am happy for you.

Collapse
 
lynnecodes profile image
Lynne

Thank you so much!

Collapse
 
robinsond7691 profile image
Robinson

Head First books are sooo good. I highly recommend anyone to look through their line up for a book on a subject of interest. They're phenomenal at teaching.

Collapse
 
lynnecodes profile image
Lynne

It was a very good read! There were many times when I thought I wasn't going to get a concept and Head First just explained it so easily!