Javascript

Object Oriented Programming (OOP)

It's all nice and dandy that I've heard this term before and can even sorta figure out what it means, but what does it really mean?

The top results in Google for OOP comes from TechTarget.com. It reads:

Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. Historically, a program has been viewed as a logical procedure that takes input data, processes it, and produces output data.

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.

.toUpperCase();

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.

Switch

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:

isNaN()

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*

But...

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:

For Loops in Javascript

This is fairly simple, we're creating a loop, something that is done over and over. The for bit tells us how long to do it for.

A for loop looks like this:

for (something; something < else; something and math) {
    stuff happens;
}

The space between the brackets is where the magic happens. Don't forget, those are semicolons separating the bits, commas won't work! Here's what they do:

Pages

Subscribe to RSS - Javascript