javascript 101 - class 1
TRANSCRIPT
WTF is JavaScript?I dunno.
Let’s learn some stuff together.
1. Getting Familiar 2. Variables 3. Functions
JavaScript console
Math
Letters/Characters
let’s get weird
Booleans
let’s get weird
1. Getting Familiar 2. Variables 3. Functions
Project Loon http://www.google.com/loon/
How does a balloon and ground control communicate?!
How can data be stored?
Refresher
23 is a Number!
“my name is Robert” is a String of characters!
47.092872635 is a Floating point number!
true and false are Boolean values
Variables Exercise
In your JavaScript console, create variables for the following data points and then call the variable name in order to make sure you did it correctly.!
altitude in meters (Float)!
latitude/longitude (String)!
# of active connections (Number)!
the Balloon’s name it chose for itself (String)
1. Getting Familiar 2. Variables 3. Functions
-Stuart (Balloon #8675309)
“Hooray; I have data! Now what…?”
How can data and commands be sent?!
How can data and commands be received?
Functions to the rescue
What is a function?
It is dumb.!
Executes the code within it!
Always returns a value!
Can be passed “arguments” with which it can process information
Let’s do something interesting
Why doesn’t this work?
Variables defined within a function are *scoped* within that function. They are *private* and are inaccessible to
anything outside of the function.
We need to be able to *pass* the data to the other function.
!This is known as *passing arguments* and, on
the other end, *accepting arguments*
Don’t be a jerk. Name things appropriately.
Functions Refresher
Functions are dumb. They don’t know much about the world unless you tell them.!
Functions can be called by adding () on the end of the function name.!
Functions are an effective method of grouping and reusing certain actions that perform a given…function.
Functions Exercise
Write two functions:!
getNearbyBalloonCount() (which is reported by the balloon and passes the balloon’s name, as well as how many balloons are near her.)!
logBalloonCount() (received by the ground station and logs to the console the values that were passed)