Learn Form Validation by Building a Calorie Counter - Step 74

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; 
      }
}

error: Your if statement should use return to end the function execution.
i don’t understand where is the problem.

the if statement should come after you call the function getCaloriesFromInputs because this functions sets the global erroe flag isError to true but here in your code you check that isError is true before it is even set to that value therefore the code inside the if statement will never run because the getCaloriesFromInputs will never be called

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.