Learn Form Validation by Building a Calorie Counter - Step 42

Tell us what’s happening:

Not going to lie, I’ve looked up other responses and I am completely lost as to what the step is asking of me. Any assistance would be great.
Thanks!

STEP INSTRUCTIONS:
Pass the string input[type="text"] to the querySelectorAll() method. Remember that you will need to use single quotes for your string, so that you can use double quotes within.

This will return a NodeList of all the text inputs in the form. You can then access the length property of the NodeList to get the number of entries. Do this on the same line.

Your code so far

function addEntry() {
  const targetInputContainer = document.querySelector(`#${entryDropdown.value} .input-container`);
  const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]'); querySelectorAll('input[type="text"]').length;
}

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 42

const entryNumber = targetInputContainer.querySelectorAll('input[type="text"]');

After you execute this line, you entryNumber will hold a NodeList object (which is similar to array). It holds all the elements in your HTML with input tag of those with attribute of [type=“text”].

To get array size, i can use Array.length
Similarly, to get NodeList size, i can use NodeList.length

You can read more about querySelectorAll() here. HTML DOM Document querySelectorAll() Method

Have fun~

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