Learn Form Validation by Building a Calorie Counter - Step 76

Tell us what’s happening:

Isn’t my if statement at the end of getCaloriesFromInputs function call? what am i miising in my code?

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function calculateCalories(e) {
  e.preventDefault();
  isError = false;

  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]);
if (isError) {
  return;
};

}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 76

1 Like

Your “global error flag” was defined on line 7 of the program. You should not be rewriting this variable.

i have edited to this;
if () {
return;
};
still not working.

Hi there!

I just removed the semicolon in the end of if statement and the code is passed. Reset the challenge step and try again.

1 Like

Your if statement needs a condition.

However you should not be reinitializing the is error flag here:

It is already defined on line 7