Learn Form Validation by Building a Calorie Counter - Step 63

I can’t seem to get the alert function to accept the template literal string and the first value of an array. I have tried many things. I will list my attempts starting with the one I think makes the least sense;

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[0]}`) *least likely IMO*
        alert(`"Invalid Input: ${invalidInputMatch[0]}"`) 
        alert(`"Invalid Input: " += ${invalidInputMatch[0]}`)
        alert(`"Invalid Input: " + ${invalidInputMatch[0]}`) *I've also tried to use the querySelector() method in conjunction with the invalidInputMatch[] as it's param*
    }
  }
}

TYIA because I’m starting to drive myself crazy with this pickle. I even spent an hour googling this as well to no avail.

Hello, can you post the link to this challenge.

Figured it out! The instructions included double quotes around "Invalid Input: " and I was stuck on the template literal being used to include the double quotes :sweat_smile:
`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[0]}`);
}

}
}`

1 Like