February – Week 4 – JavaScript

“JavaScript is a language with more than its share of bad parts.”
― Douglas Crockford, JavaScript: The Good Parts

You’ve been rumbled. Those first few tentative yet glorious steps led to a darkening realisation. Your website has no brain – even Frankenstein’s monster had a brain – back to the sandbox with you! It’s time to learn JavaScript (and by extension it’s popular library – jQuery). Some people may suggest a jQuery first approach, I don’t agree, JavaScript is a massive sprawling investment, and after 6 months I’m still a beginner. Best to start early right?

We’ll get to jQuery soon and you’ll see why (it makes communication between the 3 languages easier). I started in at – you guessed it – Codecademy, however I’ll admit, I didn’t finish it in one stretch, I came back intermittently. I struggled with some of the later tasks, again I’d recommend not sneaking a look at other people’s answers.

I quite like the Codecademy course, once you’ve finished it you may even feel you still don’t know how to write in JavaScript. That’s fine, what we’re looking for is an introduction to the general concepts a programmer needs in ANY language. (Variables, primitives, loops etc.). People seemed concerned with how much Maths may be required, because like me, they believe it’ll hinder them. Well I found that perhaps you do start at a slight disadvantage, however if you can think logically and enjoy problem solving, well these things are more important. To me a program does the maths for you, the hard part is not the writing of the equation, it’s piecing together the input to create the expected output. (see the infamous FizzBuzz program what the hell’s modulo %! you ask? You’ll get it.) I highly recommend you at least finish with an understanding of FOR loops, which I’ve used to solve a lot of programming related questions. (The 3rd block on the CA website).

Finished? This is a busy week but at least we can finally make things spin and explode. (You can take a look at this code I wrote for a spinning box. You can see it in action here. We’ll come back to it a little bit later.) Back to the Sandbox then, start the jQuery course. It’s a lot shorter than the JavaScript course, it’ll give you some practical application for your website. Remember that jQuery is not a language but a JavaScript library.

Here in JavaScript I’m storing a HTML element:

var savedElement = document.querySelectorAll("#first p.someText");

The same command in jQuery:

var savedElement = $("#first p.someText");

We can therefore see communicating with the DOM is easier when using jQuery. (Don’t forget to load the library first). If you’ve survived this far, you’ve come a long way already. You may as well keep going, I did, confused, battered and on two feet.

1. Start learning JavaScript
2. Finish the jQuery course
3. (GA)Dash – Project 2

Leave a Reply