what are we supposed to return here?
My code so far:
function calculateCalories(e) {
e.preventDefault();
isError = false;
if(isError){
const breakfastNumberInputs = document.querySelectorAll("#breakfast input[type='number']");
const lunchNumberInputs = document.querySelectorAll("#lunch input[type='number']");
const dinnerNumberInputs = document.querySelectorAll("#dinner input[type='number']");
const snacksNumberInputs = document.querySelectorAll("#snacks input[type='number']");
const exerciseNumberInputs = document.querySelectorAll("#exercise input[type='number']");
const breakfastCalories = getCaloriesFromInputs(breakfastNumberInputs);
const lunchCalories = getCaloriesFromInputs(lunchNumberInputs);
const dinnerCalories = getCaloriesFromInputs(dinnerNumberInputs);
const snacksCalories = getCaloriesFromInputs(snacksNumberInputs);
const exerciseCalories = getCaloriesFromInputs(exerciseNumberInputs);
const budgetCalories = getCaloriesFromInputs([budgetNumberInput]);
return calculateCalories(e);
}
}
The question is:
Your
getCaloriesFromInputs
function will set the global error flagisError
totrue
if an invalid input is detected. Add anif
statement to yourcalculateCalories
function that checks the truthiness of your global error flag, and if it is truthy then usereturn
to end the function execution.