Learn Form Validation by Building a Calorie Counter - Step 63

Tell us what’s happening:

I don’t understand where I’m going wrong? I don’t understand where I’m going wrong? I tried to edit the code many times but it still doesn’t work?

Using a template literal, in your if block, call the alert() function to tell the user "Invalid Input: " , followed by the first value in the invalidInputMatch array.

Your code so far

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

/* file: styles.css */

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

function getCaloriesFromInputs(list) {
  let calories = 0;

  for (const item of list) {
    const currVal = cleanInputString(item.value);
    const invalidInputMatch = isInvalidInput(currVal);

    if (invalidInputMatch) {
      alert(`Invalid Input: ${invalidInputMatch[]}`)
    }
  }
}

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 63

Hello @nguyenvanduydev001 !

It appears the first value of the array is missing in the code.

Remember the first value starts at 0, the second one would be 1, etc.

I hope this helps you.

Wishing you good progress on your coding journey. :slightly_smiling_face: