Learn Form Validation by Building a Calorie Counter - Step 49

Tell us what’s happening:

It keeps saying that I must access the innerHTML property of targetInputContainer.
But my code is correct.

Your code so far

 const HTMLString = `
  <label for="${entryDropdown.value}-${entryNumber}-name">Entry ${entryNumber} Name</label>
  <input type="text" id="${entryDropdown.value}-${entryNumber}-name" placeholder="Name" />
  <label for="${entryDropdown.value}-${entryNumber}-calories">Entry ${entryNumber} Calories</label>
  <input
    type="number"
    min="0"
    id="${entryDropdown.value}-${entryNumber}-calories"
    placeholder="Calories"
  />`;
let target = document.getElementById("targetInputContainer");
target.innerHTML += HTMLString;

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 49

You shouldn’t be creating a target variable. Just concatenate directly onto targetInputContainer.

1 Like

you’re doing great so far, although they need you to solve the code in a different way. you should read what they want slowly , you are trying to access the innerHTML of target but they need you to access the innerHTML of targetInputContainer. dont’t hard code it, i hope my answer helps

Tthank you but it still doesnt work with

document.getElementById("targetInputContainer").innerHTML += HTMLString;

→ Your addEntry function should access the innerHTML property of targetInputContainer

The instructions are perhaps a little confusing as the example given in the challenge description isn’t exactly the correct approach for this case.

There is no element with an id attribute of targetInputContainer, so you can’t use the getElementById method here. Instead it is a variable, so you can concatenate directly using the variable name and innerHTML property alone.

2 Likes

It happens quite frequently that the examples given in the challenge description are the incorrect approach. It would be great if freeCodeCamp reviewed the examples and gave better, more pertinent ones perhaps. Otherwise students can go in circles for ages, which is quite frustrating.

2 Likes

It took me a few minutes to figure this one out too, and the result is relatively simple. I do think some of the issue is related to how to the question is worded. :thinking: