This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CAVESOFCLARITY = function (caves) { | |
var sandScript = ""; | |
caves.setSandScript = function (message) { | |
sandScript = message; | |
}; | |
return caves; | |
}(CAVESOFCLARITY); | |
//Notice how we are passing the CAVESOFCLARITY module, which was recently created in another code sample. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var year = 2014; | |
var CLASSLIST = function (classYear){ | |
var maleStudents = 15, | |
femaleStudents = 20; | |
return { | |
yearBookTitle: function () { | |
return "Congradulations year of " + | |
classYear + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var CLASSLIST = function (){ | |
var maleStudents = 15, | |
femaleStudents = 20; | |
return { | |
amountOfStudents: function () { | |
return maleStudents + femaleStudents; | |
}, | |
CURRICULUM: { | |
classStart: "September 15th 2014", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TARRYTOWN = { | |
knights: 100, | |
citizens: 500, | |
stapleFood: "mutton chops", | |
alertTheLord: function() { | |
alert("We need help my lord, please send reinforcements!") | |
}, | |
KINGSKEEP: { | |
calvary: 25, | |
knights: 200, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var passengers = [ ["Thomas", "Meeks"], | |
["Gregg", "Pollack"], | |
["Christine", "Wong"], | |
["Dan", "McGaw"] ]; | |
var modifiedNames = passengers.map( | |
function (cell) { | |
return cell[0] + ' ' + cell[1]; | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list = document.getElementById('friendsList'), | |
friends = ["Andre", | |
"Pedro", | |
"Johnny", | |
"Fer", | |
"Tiago", | |
"Danny"], | |
fragment = document.createDocumentFragment(), | |
element; | |
for(var i = 0, l = friends.length; i<l; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sansTemple(floor){ | |
var happensNext; | |
switch(floor) { | |
//Notice how you can use a stacking method to reduce redundency in cases. Now lower level also works for the basement cond. | |
case "lower level" : | |
case "basement" : | |
welcomeMessage = "Welcome to the basement!"; | |
case 1 : | |
welcomeMessage = "You have entered the First Floor!"; | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Tool(name, type, use, cost) { | |
this.name = name; | |
this.type = type; | |
this.use = use; | |
this.cost = cost; | |
//You can also add inherited functions here for everything created using this constructor | |
this.useTool = function () { | |
alert("Alright, be careful with that "+this.name+"!"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.checkFor = function (input) { | |
var result = 0; | |
for (var i = 0; i<this.length; i++) {//use this to check for the length of the actual string | |
this.charAt(i) == input ? result++ : false; //we can use a ternary conditional here. | |
} | |
return result; | |
}; | |
console.log("This is a good string".checkFor("o")); //Now we can use the new method on a string and log it out. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fridge = { | |
addItem: function(name, type, expirationDate, healthRating) { | |
this[name] = {type: type, expirationDate: expirationDate, healthRating: healthRating}; | |
}, | |
removeItem: function(name){ | |
var recentlyRemoved = delete this[name]; | |
} | |
}; | |
fridge.addItem("bannana", "fruit", "2 weeks", "100"); | |
fridge.addItem("steak", "meat", "1 weeks", "70"); |