【发布时间】:2020-12-18 16:14:50
【问题描述】:
在第 3 章中,有这个 Hummus 食谱示例,我真的不明白的是这样的代码:
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");
};
我添加了一些 console.log 以尝试更好地跟踪进度并了解此处实际发生的情况,但我无法理解它。我的意思是这里的预期结果是什么?
【问题讨论】:
标签: function eloquent console.log progress recipe