A Deeper Plunge Into JavaScript with Codecademy: The Beauty of the Switch

As I mentioned in a previous post, I have been exploring the world of programming starting with JavaScript via Codecademy.  Today is my fifth day of learning and it seems to be pretty smooth sailing (albeit with some definite hiccups!).  I haven’t been spending a huge amount of time each day, approximately around 1 hour per daily session. Thus far, I have explored the very basics (i.e. prompts, strings, numbers, console.log, etc.), functions, ‘for’ loops, ‘while’ loops, and if/else statements, to name a few.

As I was programming, I began to run into some forgetful moments.  Yes, the hints on Codecademy are excellent and Google is a beaut, but I was starting to get a bit annoyed.  There were times where I felt that the exercise I was being asked to do kind of skipped over some instructions (alternatively, this may simply have been because I had forgotten a previous task or simply wasn’t paying attention with the instructions or tips provided for the exercise).  One particular annoyance occurred during my exploration into “while” loops. I went from the very simple programming of very basic while loops, to having to suddenly write a while loop that logs “I’m looping!” to the console three times without using console.log calls.  Sure, for you programmer masterminds out there, a very simple task. For me, a pathetic beginner who feels a great achievement writing a VERY easy while loop, this was a very daunting task.  The exercise had some of the loop previously written, but I became quite confused with empty brackets. I couldn’t recollect this being mentioned before, so I was at a bit of a standstill.  I checked the Hint, but was still confused. I ended up calling upon my husband for some back up (and yes, he did look at me as if he was trying to instruct a small child…).  Needless to say, I figured out how to do the task.  Afterwards, I decided that perhaps part of my difficulty was that I kept forgetting what I had learned previously. I then decided to quickly go back and review the courses (which I LOVE about Codecademy). As I reviewed the previous courses and exercises, I began to jot down little reminder notes.  Doing the process a second time and now having notes to refer back to is immensely useful. As I have proceeded into more lessons, I can now quickly look up a note I did and be able to complete the activity more easily.

Enough of my complaining, however!  There was one thing that I did today that I absolutely loved (and I’m not entirely sure why…): the switch statement!  The switch statement basically allows you to design a specific number of options (called case(s)), and then check a variable or expression against them to see if there is a match.  If it matches, the program performs a specific action that you have specified.  If it doesn’t match, then you execute a default option specified by you. We had a series of exercises introducing and reinforcing the switch statement.  It was probably the easiest and quickest thing I have picked up on thus far (aside from the basics, like console.log and prompts).  Codecademy broke the switch statement into chunks, having you first complete a small part, then adding on until you have to make your own, which for whatever reason, I found immensely entertaining.  So…I guess what I’m saying is if you are finding yourself frustrated with the if/else or for loops or while loops while learning JavaScript, take a breather and look up the switch statement. Play around and have fun with it.  Make yourself giggle.  I sure did… 😉

Below is a … um … G version of a switch I wrote. He he.



Happy programming!

Leave a Reply

Your email address will not be published. Required fields are marked *