Created
June 8, 2016 15:02
-
-
Save JoeShep/b7aff40ffc495f750a7c938236fd543a to your computer and use it in GitHub Desktop.
Sandwich Maker example
This file contains hidden or 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
console.log(Sandwich); | |
var sandwichCost = Sandwich.getSandwichPrice("cheese"); | |
var toppingCost = Sandwich.getToppingPrice("captainCrunch"); | |
var output = document.getElementById("sandwich"); | |
output.innerHTML = sandwichCost + toppingCost; |
This file contains hidden or 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 Sandwich = (function() { | |
var prices = {"pb&j": 2.00, "cheese": .75}; | |
return { | |
getSandwichPrice: function(sandwich) { | |
return prices[sandwich]; | |
} | |
}; | |
})(); |
This file contains hidden or 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 Sandwich = (function(origSand) { | |
var toppingPrices = {"whippedCream": .50, "captainCrunch": .10}; | |
origSand.getToppingPrice = function(topping) { | |
return toppingPrices[topping]; | |
} | |
return origSand; | |
})(Sandwich); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment