Learn Form Validation by Building a Calorie Counter - Step 45

Tell us what’s happening:

The string has been passed Im not sure what else is missing…

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);
  
}

// 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/131.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 45

Hi there!

The length property doesn’t goes within the query selector

Hi there!
Look again:

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.

First: return a nodelist
Second: get a length of this list

querySelectorAll('input[type="text"]'.length);

As said above, replace .length

What do you do to return a nodelist

Passing the string input[type="text"] to the querySelectorAll() method

The tutor prompt replies with " You should access the length property of your querySelectorAll() ." when .length is removed

The above line of code return a nodelist, except you have the .length property in wrong palce. Remove it from inside the querySeletorAll() and add it immediately after round braces.

2 Likes

i did this but my code is still wrong

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

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Help button located on the challenge. This button only appears if you have tried to submit an answer at least three times.

The Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.