Created
April 17, 2019 02:34
-
-
Save akaomy/700fa6ec174f11a947979b72976033cb to your computer and use it in GitHub Desktop.
Eloquent JS notes
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
// 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