Learn Form Validation by Building a Calorie Counter - Step 74

Tell us what’s happening:

So I’m doing the newJS curriculum, on this situation and it requests:

Step 74

Your getCaloriesFromInputs function will set the global error flag to true if an invalid input is detected. Add an if statement to your calculateCalories function that checks the truthiness of your global error flag, and if it is truthy then use return to end the function execution.

however I can’t seem to return correctly, if I return “calculateCalories”, “calculateCalories(e)”, " getCaloriesFromInputs", empty return, nothing passes.
Can you help me understand what’s wrong?

### Your code so far

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) {
    isError = true;
    return getCaloriesFromInputs;
  }

}

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 74

You don’t need to do this. You already know that isError is true because you are testing for it with if (isError). Granted, I guess it doesn’t do any harm to add this line, but the tests don’t like it, so remove it.

You don’t need to return a value, you can just return and nothing else. Again, it probably doesn’t really do any harm to return getCaloriesFromInputs, but the tests aren’t expecting it, so you won’t pass if you do.

5 Likes

if (isError) {
return;
}

1 Like

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