Learn Form Validation by Building a Calorie Counter - Step 22

Tell us what’s happening:

Hello, I’m trying to understand why in this “for” loop we check if strArray[i] has +, - or " "? Shouldn’t it be to check if strArray has it? why do we need the “[i]” if “i” is only a varieble we made for the loop to star, check a condition and stop? I’m confused and can’t seem to find an answer…

Your for loop should see if strArray[i] is found in ["+", "-", " "]

Your code so far

function cleanInputString(str) {
const strArray = str.split(‘’);
const cleanStrArray = ;

for (let i = 0; i < strArray.length; i++) {
if (![“+”, “-”, " "].includes(strArray));
}
}

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 22

Is it just because it’s inside the loop? Does that mean any variable we call inside the loop needs the “[i]”?

So from what I understand you use to select something from an array, but since the number of calories might change depending on what the user inputs, we set it to the value of “i” because it’s going to have the length array the user inputs.

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