Learn Form Validation by Building a Calorie Counter: Step 49 | freeCodeCamp.org
Hi, I’m completely lost with this step I still don’t understand what innerHTML is and how to use it, all the code I am about to include is from the previous step. All help is appreciated it, Thank you.
This is the problem:
Add your new HTMLString
to the targetInputContainer
by using the innerHTML
property. Remember to use the +=
operator to add to the existing HTML instead of replacing it.
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>
<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"
/>`;
}