Learn Form Validation by Building a Calorie Counter - Step 66

Tell us what’s happening:

can anyone please show the actual code because i was trying from past one week. but i am not getting the accurate code

Your code so far

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

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

function getCaloriesFromInputs(list) {
  let calories = 0; // Initialize total calories

  for (const item of list) {
    const currVal = cleanInputString(item.value); // Clean the input
    const invalidInputMatch = isInvalidInput(currVal); // Check for invalid input

    if (invalidInputMatch) {
      alert(`Invalid Input: ${invalidInputMatch[0]}`);
      return null; // Exit if invalid input is found
    }

    const numberValue = Number(currVal); // Convert currVal to a number

    // Continue only if the number is valid
    
      calories += numberValue; // Use addition assignment to update the calories total
    
  }

  return calories; // Return the total calories
}


// User Editable Region
/* file: styles.css */

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 66

We don’t post solutions on this forum because we want to encourage everyone to learn how to code through their own effort. However we can help you by suggesting some steps forward.

What is the hint you are getting and what is the issue you are having following that?

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