function calculateFoodOrder(numAnimals = 0, avgFood = 0) {
if(Number.isInteger(numAnimals) && Number.isInteger(avgFood) && numAnimals > 0 && avgFood > 0 ) {
return numAnimals * avgFood;
}
return -1;
}
const calculateFoodOrder = (n = 0, f = 0) => (Number.isInteger(n) && Number.isInteger(f) && n > 0 && f > 0 ? n * f : -1);
console.log(calculateFoodOrder()); // -1
console.log(calculateFoodOrder(-1,4)); // -1
console.log(calculateFoodOrder(1,3));//3
console.log(calculateFoodOrder([], 200)); // -1
console.log(calculateFoodOrder(Infinity, 200)); // -1
function calculateFoodOrder(numAnimals, avgFood) {
var numAnimals = 10;
var avgFood = 3;
if (numAnimals < 0) {
return -1;
} else if (numAnimals = String) {
return -1;
} else if (avgFood < 0) {
return -1;
} else if (avgFood = String) {
return -1;
} else {
return numAnimals * avgFood;
}
}
console.log(calculateFoodOrder());
if (typeof numAnimals === "string") { return . . . }
console.log( calculateFoodOrder(значение1, значение2) )
console.log( calculateFoodOrder(550, 241) ) // пример
function validArgument(n) {
return typeof n === 'number' && n >= 0;
}
function calculateFoodOrder(numAnimals, avgFood) {
if (validArgument(numAnimals) && validArgument(avgFood)) {
return numAnimals * avgFood;
}
return -1;
}