Learn Form Validation by Building a Calorie Counter - Step 61

Tell us what’s happening: I don’t see why my code doesn’t work. Please help.

Browsers have a built in alert() function, which you can use to display a pop-up message to the user. The message to display is passed as the argument to the alert() function.

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

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

### Your browser information:

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

### Challenge Information:
Learn Form Validation by Building a Calorie Counter - Step 61

Welcome to the forum @jobanibusiness

How is your code accessing the first match in the array?

Happy coding

1 Like

Thank you, I was able to solve it.
alert(Invalid Input: ${invalidInputMatch[0]});