Complex Arrays

We've touched on arrays before. Now we're going deeper.


var myArray = [1,2,3,4,5];

Heterogeneous Array

An array with mixed data types incl numbers, strings and booleans.

var myArray = [1,true,"tree",4,5,"sticks"];

Two Dimensional Array

Arrays within arrays. The simplest of these look kind of like a data table. Here's an example:

var my2DArray = [['Dog','Cat','Bird'],['Shnautzer','Siamese','Parrot'],['Doberman','Calico','Budgie']];

Airport Customs Game

For the final part of lesson 5 of Codecademy's Javascript course you have to write your own little "operators" game. Mine is posted below. We also learned a new command.


It changes the output of the previous function to all caps so the user can enter "yes", "Yes" or "YES" and any answer is accepted.

Logical Operators

Logical operators are used when I have more than one input and I need to decide how to combine those inputs. A simple logical operator example would be deciding to buy electronics. You have three basic options: quality, cost, age. Logically (I wanted to say obviously, but having worked B2B this might not always be that obvious to everybody) you can't have all three at the same time, so you make a couple choices. Here's a basic look at some of our thinking process to make this very logical decision:


Switch works like if/else but instead of writing multiple entries in curly brackets it allows us to create something akin to a css definition list, with a term and a definition. Definition lists look something like this:


This simple function checks to see if something "is not a number". It returns true if the input is not a number.

isNaN(24) => False // 24 is a number
isNaN("cat") => True // "cat" is a string
isNaN("24") => False // "24", even though a string, is converted to a number by Javascript
isNaN(true) => False // true = 1
isNaN(NaN) => True // Not a Number is Not a Number ;)
isNaN(undefined) => True*


While Loops

While loops are similar to for loops in that they loop over a piece of code. The only difference is that a for loop continues until a condition is met and a while loop continues while a condition is met.

Quick sideline in this lesson. When we write boolean = true we can also just write boolean.

Simple while loop example:


Subscribe to I Learn Code RSS