Learn Form Validation by Building a Calorie Counter - Step 22

Tell us what’s happening:

### Your code so far

for (let i = 0; i < strArray.length; i++) {
if(!strArray.includes([‘+’ , ‘-’ , ’ ']))
{
cleanStrArray.push(strArray[i]);
}
}
}
Problems:
1- i think the code is correct but its not passing through
2-it give me this warning " Your for loop should use !["+", "-", " "].includes() "
3-the warning makes no sense i tried doing what it told me that went nowhere.
So i have a question can someone tell me what is wrong is it my code or is it the testers

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 22

1 Like

hi your code is correct but the only problem is your not checking strArray items with the provided for loop and its index that is i so you need to put sth inside the includes() function to work with the loop hope it works I tried not to mention any direct solution for your good.

1 Like

thank you I figured it out.

1 Like

hello i need your help to figure it out, been trying for 2days now

ok so this is the correct thing if(!strArray.includes([‘+’ , ‘-’ , ’ ']){}but testers say that the inverse is correct someone should really change it cuz it really is confusing. You can look at docs like MDN Web Docs for more examples and to really understand how certain methods work.

anyways, thanks. i figured it out and it passed the checker.

i think they should update the checker to pass different instances of writing it correctly.

If you’re stuck like I was, just head back to https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8 and skip Step 22. It worked for me!

could you help me out here, i tried mimicking everything said above but even still had no luck. Thank you in advance.

ok so i was asleep but this problem is wrong you can go to MdN web docs and search the .include() method. The problem is i think the person who made this step forgot how to use the .includes method so firstly reset your lesson then inside the for make an if statement that has the condition: ![“+”,“-”“”].includes(strArray) (which the test say is right but its wrong still this is how you pass).Then figure the rest from here since we cant give the full solution.

4 Likes

Thank you so much, I was so confused because I had took java and was like why is it in reverse, they should fix that step

1 Like

Interestingly this worked out; but it is obvious the algorithm is flawed

when you are using not symbol(!) we should write like that only.

So…now im really stuck even after reading this. This is my code currently

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

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

Thank you very much, I actually had the solution that was in the first post, but after getting the hint by the tester and trying out the solutions on this threads, its become a jumbled mess for me…send help lol

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