Learn Form Validation by Building a Calorie Counter - Step 50

Tell us what’s happening:

it says that Your new label element should have a for attribute set to ${entryDropdown.value}-${entryNumber}-calories. but i think i include that

Your code so far

<!-- file: index.html -->

/* file: styles.css */

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

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" /><br>
  <label for="${entryDropdown.value}-${entryDropdown}-calories">Entry ${entryNumber} Calories</label>
  `;
}

// User Editable Region

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 50

1 Like

The for attribute should take this value

${entryDropdown.value}-${entryNumber}-calories

Check what you’re missing.

1 Like

when i change the Dropdown to Number it says that You should not modify your existing elements.

1 Like

Post the modified code.

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" /><br>
  <label for="${entryDropdown.value}-${entryNumber}-calories">Entry ${entryNumber} Calories</label>
  `;
}

You should not add or delete portions of code that you are not instructed to; doing so will cause you more problems.

The line break was not required.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.