Hello, World!
Javascript
What is Javascript?
Variables
Pay attention to types:
Exercise
Tell the following story using variables:
Alex has $100
Alex buys a burrito for $8
Joe repays Alex the $50 he lended him. Joe has
$200 leftover.
Alex pays Molly $20 to babysit his kids
Molly sees a movie with Joe for $10
What is the sum of Molly, Alex, and Joe's money?
Choice
Exercise
You are given two variables, x and y
Write code that ensures that x will always be
larger than y, swapping them if necessary
Iteration
Exercise
Write code (using loops!) that prints:
The values from 0 to 10 (inclusive)
The values from 1 to 10 (inclusive)
The values from 4 to 19 (inclusive)
Even values between 5 and 12 (inclusive)
Exercise
The fibonacci sequence is given as:
0, 1, 1, 2, 3, 5, 8, 13, .
Write javascript to print the first 50 fibonacci
numbers
Exercise
Write code to do the following:
Your code should count from 0 to 100
If the current number is divisible by 3, print fizz
If the current number is divisble by 5 print buzz
If it is divisible by 3 and 5, print fizzbuzz
Otherwise, print the number
Functions
f(x) = 3x + 2
Exercise
Change your fibonacci code to be a function. The
function should take in a value called N and return
the Nth fibonacci number. So if N = 1 then return
0, if N = 2 then return 1, etc.
Write a function called mult that takes in two values,
x and y, and returns the product. You may not use
* to accomplish this.