Learn Form Validation by Building a Calorie Counter - Step 41

Tell us what’s happening:

I am on Step 41 of Learn Form Validation by Building a Calorie Counter. The website preview has stopped showing for some reason and I’m getting this error under the “check your code” box. Another forum had the same code and was correct?

SyntaxError: unknown: Unexpected token, expected “,” (21:55) 19 | function addEntry() { 20 | const targetId = “#” + entryDropdown.value; > 21 | const targetInputContainer = document.querySelector(${targetId} .input-container); | ^ 22 | }

Your code so far

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

function addEntry() {
  const targetId = "#" + entryDropdown.value;
  const targetInputContainer = document.querySelector(${targetId} .input-container);
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 41

3 Likes

You’re missing something, take a close look at the example again:

const templateLiteral = `Hello, my name is ${name}~!`;
const targetInputContainer = document.querySelector(${targetId} .input-container);

There is a marker that tells JS it’s a template literal.

Template literals are denoted with backticks `` , as opposed to single or double quotes.

2 Likes

Thank you! :smiley: I had put the backticks there before but think I had a different combination inside, and then another post confused me. For anyone looking for the solution, it’s as simple as pkdvalis presented:

--- solution removed ---
1 Like

Please don’t post solutions, thanks!

Forum is more for guidance, don’t want it to just be answers/spoilers

1 Like

Oops no worries! Thank you again!

1 Like

${targetId} .input-container
use Shift+~