我试图通过此功能将值返回到控制台。但是这个功能只是回归" undefined"在相关HTML文件的控制台中。
function calculateFoodOrder(numAnimals, avgFood) {
var animals = Number(numAnimals);
var food = Number(avgFood);
if (isNaN(animals)|| animals<0) {
return null;
}else if(isNaN(food)|| food<0){
return null;
}else{
var total= animals*food;
return total;}}
&#13;
答案 0 :(得分:0)
以下是运行此功能的更好方法:
function calculateFoodOrder(numAnimals, avgFood) {
var total = numAnimals * avgFood;
return isNaN(total) || total < 0 ? false : total;
}
console.log(calculateFoodOrder(1, 10));