Learn Form Validation by Building a Calorie Counter - Step 79

Tell us what’s happening:

I’m note sur what I’m doing wrong here. please help. step 79

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;
const surplusOrDeficit = remainingCalories >= 0 ? "Surplus" : "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/123.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 79

Im getting an error that says " You should have a ternary operator that checks if remainingCalories is less 0 ."

Please talk to us about how the instructions or error message is confusing. Thanks

my code is not passing and i cant figure out what im missing

Ok, can you talk to us about how the instructions or error message is confusing for you?

I’m sorry i dont understand your question. Could you rephrase it ?

It’s obvious that your code isn’t working, otherwise you wouldn’t ask for help. What about this Step has you confused?

Hi @magnan245

You should have a ternary operator that checks if remainingCalories is less 0.

Your code is checking if remainingCalories is greater than or equal to zero.

Happy coding

I have the " : " which is for the else statement for remainingCalories less 0
maybe I dont understand it. How sould I write the operator to check remainingCalories is less 0 ?

The comparison is incorrect, the rest of the code looks right.

ok. Could you please provide me some guidance on how to write the comparison ?

Here is some code as an example.

const anyBonusPayments = monthlySales >= 9999 ? “Everyone gets a bonus” : “No bonuses this month”.

This is checking if monthlySales is greater than or equal to 9999.
If the equals sign is removed, then monthySales needs to be 10000 or greater for the sales team to get their bonus.

that is exactly what i wrote in my code. i tried without the = but still not passing

What is your updated code? The code you posted doesn’t check if the remainingCalories is less than 0

const surplusOrDeficit = remainingCalories > 0 ? “Surplus” : “Deficit”;

> means greater than

1 Like

yes. that is is why the first string is “Surplus”

The instructions:

You should have a ternary operator that checks if remainingCalories is less 0 .

1 Like

ok. I tried the other way and it worked.

1 Like