Open Chrome Developer Tools
Click on the Console
Dave "Dave"
name = "Dave" name
34 34 + 2 34 - 2 34 * 2 34 / 2 34 % 2 34 * 2 + 2 34 * (2 + 2) 34*(2+2)
age = "34" age = 34 age age * 2 age / 2 age
age = age + 1 age += 1
birthday = function(number) { number = number + 1 return number }
birthday(34) birthday(age) age
age = birthday(age)
birthday = function(number) { number = number + 1 candles = number return number }
age = 34 birthday(age)
age candles
Right now our birthday function is just an incrementor, which isn't very useful. Let's try to update our age value inside the function itself.
birthday = function(age) { age = age + 1 candles = age return age }
age = 34 birthday(age)
age candles
birthday = function(then) { now = then + 1 return now }
birthday(34) then = 34 birthday(then) now then
var birthdate = new Object(); birthdate.month = 06; birthdate.day = 13; birthdate.year = 1980;
birthdate
var birthdate = new Date(1980,06,13,0,0,0,0);
var invitation = { name: "Lucy", coming: "yes" }
var invited = ["Lucy","Tibby","Autumn"];
invited[1] invited[0]
var invitations = [ { "name": "Lucy", "coming": "yes", "age": "9" }, { "name": "Tibby", "coming": "yes", "age": "7" }, { "name": "Autumn", "coming": "maybe", "age": "34" }];
invitations.name; invitations[1].name; console.log(invitations[1].name);
Object.keys(invitations) Object.keys(invitations[1])
for (var i = 0; i < invitations.length; i++) { console.log(invitations[i].name); };
invitations.forEach(function(entry) { console.log(entry) })
invitations.forEach(function(entry) { console.log(entry.name) })
We'll step through each person, check if they are coming and then print a message using string concatenation.
for (var i = 0; i < invitations.length; i++) { coming = (invitations[i].coming); if (coming == "yes") { console.log(invitations[i].name + " is coming!"); } };