Skip to content

Instantly share code, notes, and snippets.

@akaomy
Created April 17, 2019 02:34
Show Gist options
  • Save akaomy/700fa6ec174f11a947979b72976033cb to your computer and use it in GitHub Desktop.
Save akaomy/700fa6ec174f11a947979b72976033cb to your computer and use it in GitHub Desktop.
Eloquent JS notes
// code inside ingrediend function can see the parameter of hummus function
// but outer - hummus function cannot see the inner bindings of ingredient function
const hummus = function(factor) {
const ingredient = function(amount, unit, name) {
let ingredientAmount = amount * factor;
if (ingredientAmount > 1) {
unit += "s";
}
console.log(`${ingredientAmount} ${unit} ${name}`);
};
ingredient(1, "can", "chickpeas");
ingredient(0.25, "cup", "tahini");
ingredient(0.25, "cup", "lemon juice");
ingredient(1, "clove", "garlic");
ingredient(2, "tablespoon", "olive oil");
ingredient(0.5, "teaspoon", "cumin");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment