Functions
Learning Objectives
- Describe a functions
- Defend using a function
- Create and call a function with and without parameters
- Differentiate an anonymous and a named function
- Pass a function... as an argument
Class Examples
function gatherIngredients() {
var ingredients = [];
ingredients.push('eggs', 'flour', 'coconut milk', 'pecans', 'rubarb', 'strawberry', 'unicorn blood');
return ingredients;
}
gatherIngredients();
var pieIngredients = gatherIngredients();
console.log(pieIngredients);
function getUtensils() {
return ['bowl', 'spoon', 'oven', 'whisker'];
}
console.log(getUtensils);
console.log(getUtensils());
function callSaul() {
return "Hey, this is Saul. What do you need?";
}
function replyToSaul() {
return "Disney is suing me for making pie. Halppppp plox!@121212121";
}
function saulSays(message) {
return message;
}
console.log(callSaul());
console.log(replyToSaul());
console.log(saulSays('FILE A RESPONSE!!!'));
function crashYourTerminal() {
}
function theVoidTheDarknessConsumesAll() {
console.log('shhhh, they are coming for you');
}
function billCatchesJames() {
console.log('STOP JAMES');
}
function lolBill() {
console.log('hahahaahahahah catch me bro');
}
billCatchesJames();
lolBill();