Learn Form Validation by Building a Calorie Counter - Step 80

Tell us what’s happening:

Hello FFC Forum,

I have run into a problem regarding the exercise on step 80.
I am sure my answer is correct but it’s not going through.

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

  const consumedCalories = breakfastCalories + lunchCalories + dinnerCalories + snacksCalories;
  const remainingCalories = budgetCalories - consumedCalories + exerciseCalories;
  
let surplusOrDeficit;
remainingCalories < 0 ? surplusOrDeficit = "Surplus" : surplusOrDeficit = "Deficit";
}

// 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/131.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 80

do not put the assignment inside the ternary please
instead you should

put the assignment on this line with the ternary on the right.

Makes sense, this way the code looks easier to read. I don’t know why we couldn’t of assigned it straight away though instead of assigning it on the next line.

Or maybe I looked into it incorrectly, because I declared the variable, then assigned it on the next line.

Thanks anyway brother

you should do it all in a single line

Thanks, I declared the variable with no value, then underneath assigned it to the variable.

It works the same, but doing it all on a single line is more compact

1 Like

Yes, you are correct! Anyway, thanks for your help!