Skip to content

Instantly share code, notes, and snippets.

@kbk0125
Last active August 19, 2022 14:07
Show Gist options
  • Save kbk0125/beee2f2286f39bda68f06bfc64739fb8 to your computer and use it in GitHub Desktop.
Save kbk0125/beee2f2286f39bda68f06bfc64739fb8 to your computer and use it in GitHub Desktop.
// generic reportOrders that shows your orders to the function
function reportOrders (minionOrders) {
if ( typeof minionOrders === "string"){
console.log(minionOrders);
}
else if ( typeof minionOrders === "object"){
for (var item in minionOrders) {
console.log(item + ": " + minionOrders[item]);
}
}
}
// A function that takes two parameters, the last one a callback function​
​function speakOrders (orders, callback) {
callback (orders);
}
// When we call the speakOrders function, we pass reportOrders as a parameter.​
// So reportOrders will be the function that will called back (or executed) inside the speakOrders function​
speakOrders ({name:"Minion1031", speciality:"Scribe"}, reportOrders);
// Console
// name: Minion1031
// speciality: Scribe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment