Slides: bit.ly/JS102
var coolTeachers = ["Pamela", "Bianca", "Brenda", "Aysegul"];
var classes = [];
classes[0] = 'HTML 101';
classes[1] = 'JS 101';
classes.push('JS 102');
classes.pop();
var i = 0;
classes[i]; // ??
classes[1];
classes.pop(); //??
classes.length;
var classes = ['HTML 101', 'JS 101', 'JS 102'];
//I took HTML 101...
for(initial counter; condition to stop; counter++){
console.log(counter); //??
}
var classes = ['HTML 101', 'JS 101', 'JS 102'];
for(var i = 0; i < classes.length; i++){
console.log('I took ' + classes[i]);
}
{}
var angelTheCat = {};
angelTheCat.furColor = "orange";
//OR
var angelTheCat = {"furColor" : "orange"};
var angelTheCat = {};
angelTheCat.furColor = "orange";
var furVariable = angelTheCat.furColor;
furVariable; //??
angelTheCat.furColor = "grey";
furVariable; //??
angelTheCat["fur color"] = "orange";
angelTheCat["fur-color"] = "orange";
var facebookFriends = {};
facebookFriends[12323] = angelTheCat;
var angelTheCat = {};
angelTheCat["furColor"] = "orange";
var keyVariable = "furColor";
angelTheCat[keyVariable]; //??
var angelTheCat = {
age: 5,
furColor: "orange"
};
var angelTheCat = {
age: 5,
furColor: "orange",
isAngelic: true,
likes: ["catnip", "milk"],
birthday: {"month": 7, "day": 17, "year": 2009}
};
var cuteCats = [
{ name: "Angel", age: 18, furColor: "grey" },
{ name: "Evil", age: 14, furColor: "red" },
{ name: "Meh", age: 12, "Fur Color": "white" }
]
cuteCats[0].name = ;//?
cuteCats[1].furColor;//?
cuteCats[2]["Fur Color"] = ;//?
var zoo = {
birds : 3,
bears: 5,
cats: 12,
}
for(var key in zoo) {
console.log(zoo[key] + ' ' + key);
}
var doll = { "innerDoll" : {} };
var doll = {
size: "large",
innerDoll: { size: "medium"}
};
doll.innerDoll.innerDoll = {size: "small"};
console.log(doll);
var add = function(a, b) {
return a + b;
};
add(5, 4);
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
nameImprover("Pamela", "fancy");
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
nameImprover("Pamela", "shiny");
nameImprover("Aysegul", "fancy");
var nameImprover = function (name, adj) {
return 'Col ' + name + ' Mc' + adj + ' pants';
};
var nameLogger = function (name, adj) {
var newName = 'Col ' + name + ' Mc' + adj + ' pants';
console.log(newName);
};
var addTwo = function(a, b) {
console.log(arguments); // logs [3,10]
return a + b;
};
addTwo(3, 10); // 13
var addMany = function() {
console.log(arguments);
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
};
addMany(3, 10, 57,...);
var nameLogger = function(name, adj) {
if(adj === undefined) adj = "Fancy";
var newName = 'Col ' + name + ' Mc' + adj + ' pants';
console.log(newName);
};
The context in which values and expressions are "visible," or can be referenced.
var mySecretFunction = function() {
var meLoveChocolate = true;
console.log(meLoveChocolate);
};
console.log(meLoveChocolate);
var momsCandies = ["Milky Way", "Cadbury eggs", "Twix"];
var keepMyCandy = function() {
var myCandies = ["Kit-Kat", "Hershey Bar", "M&Ms", "Snickers"];
console.log("I'm available inside the function ", momsCandies);
};
console.log(myCandies);
var momsCandies = ["Milky Way", "Cadbury eggs", "Twix"];
var shareMyCandies = function() {
myCandies = ["Kit-Kat", "Hershey Bar", "M&Ms", "Snickers"];
};
console.log(myCandies);
var g = "global";
function go() {
var l = "local";
var g = "in here!";
alert(g + " inside go");
}
go();
alert(g + " outside go");