Learn Form Validation by Building a Calorie Counter - Step 49

That doesn’t explain why you think it is good to put your new line of code outside of the function you are working on.

If I’m not right, I can put it in the funcion.

You should make changes for a reason. Guess and check can be helpful for exploring but debugging works best with intentionality.

There can be only one intention here: to complete the task correctly.

Ok, so how does deleting both } help accomplish that intention?

I don’t think so. But I am confused by the developer console, which requires placing an element with attributes on a separate line. What is this line? Inside the function or outside it?

Do you have a reason to believe you should put code outside of the function on this Step?

You may be missing some key knowledge about syntax and structure from the first JS projects.

I have no reason for believing in it. I only think how better to fulfil the task.

Why might putting code outside of the function help you or not help you better fulfill the task then?

I don’t know why. I think only.

Well, what are you thinking about that?

I’am thinking what is the error in my code now:

{entryDropdown.value} .input-container`);
  const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
  const HTMLString = `
  <label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>`;
  <input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" </input>
}

You cannot put raw HTML into JS code.

@Dennis-code153 You need to add the input element in a new line after the label element within the templete literals. Did you know the template literals?
Note: you have learned about that in previous curriculum challenges.
Edit: if you didn’t know about your previous code. Then with only passing challenges, you are not learning anything.

1 Like

can you indicate which part of the code is the template literal? it’s important as you need to add more code inside the template literal

1 Like

The tamplate literal is that one which comes from the previous step 48, am I right?
Here it is:

function addEntry() {
  const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
  const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]').length;
  const HTMLString = `
  <label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>`;
}

that is a function. Which part of that is the template literal?

Not all of that is the template literal, no

So it is:

<label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>`;
}

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 (').