st3llz
February 21, 2024, 4:43am
1
Tell us what’s happening:
I need help to understand, scanned all of the posts and I am still unsure what exactly I am missing.
Your code so far
This is my code
function clearForm() {
const inputContainers = Array.from(document.querySelectorAll(‘.input-container’));
for (i = 0; i < inputContainers.length; i++) {
inputContainers[i].innerHTML = ‘’;
}
}
WARNING
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
You will need to take an additional step here so the code you wrote presents in an easy to read format.
Please copy/paste all the editor code showing in the challenge from where you just linked.
function clearForm() {
const inputContainers = Array.from(document.querySelectorAll('.input-container'));
for (i = 0; i < inputContainers.length; i++) {
inputContainers[i].innerHTML = '';
}
}
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 90
Learn to Code — For Free
hi! what’s the question?
querySelectorAll selects all the DOM elements with class .input-container using an Array.from method, and store them in the const inputContainers.
Then you iterate over them with a for loop and change their inner HTML to an empty string, kinda deleting them from the HTML view.
Teller
February 21, 2024, 5:34am
3
Hi @st3llz
The reason your code is failing is because the tests are not finding the for ...of
loop asked for in the instructions.
Happy coding
In the original posted loop you need to initalize the i variable with let i
st3llz
February 22, 2024, 3:11am
5
function clearForm() {
const inputContainers = Array.from(document.querySelectorAll(‘.input-container’))
for (let i = 0; i < inputContainers.length; i++)
inputContainers[i].innerHTML = ‘’;
}
I still get the error
Sorry, your code does not pass. Keep trying.
Your for...of
loop should iterate through the inputContainers
array. The loop’s variable name should be container
.
I re-typed the whole code, and cannot understand how the test is not finding the for…of loop
st3llz
February 22, 2024, 5:15am
6
I finally figured it out!!!
1 Like
system
Closed
August 22, 2024, 5:15pm
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.