Learn Form Validation by Building a Calorie Counter - Step 61

Tell us what’s happening:

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

if (invalidInputMatch[i]) {
      return alert(`"Invalid Input:"`, invalidInputMatch[i]);
    }

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 61

Please note the italicised portion of the requirement

if (invalidInputMatch) {

 `alert(${invalidInputMatch[i]} "Invalid Input: ")`;

}

I tried the above solution, but it still doesn’t work? Can you help me more

Do you understand how to use a template literal. Here is an example:

if (a < b) {
  alert(`a: ${a} is less than b: ${b}`)
}

Here, if a has a value of 23 and b has a value of 33, the alert would say

a: 23 is less than b: 33

Tell us what’s happening:

You should use template literal syntax to display the first value in the invalidInputMatch array after the Invalid Input: text.

Your code so far

if (invalidInputMatch) {
          alert(`Invalid Input: , ${invalidInputMatch[i].value}`);
}

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 61

as you are using a template literal, you don’t need to add a comma after the colon

You should use template literal syntax to display the first value in the invalidInputMatch array after the Invalid Input: text.

if (invalidInputMatch) {
          alert(`Invalid Input:, ${invalidInputMatch[0].value}`);
}

the back tick is not displaying when I post it, but its after
alert(’ and ')

remove the comma


I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

if (invalidInputMatch) {
          alert(`Invalid Input: ${invalidInputMatch[i].value}`);             
}

and remove the .value, also it wants the first value inside the array

1 Like

Hey, Thanks all for your time. I figured it out this way.

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

this step is step 63on my account. I dont know why this discrepency and i have a syntax error and i dont know where

the projects are changed often as it is still in beta, please open your own topic to ask for help