Learn Form Validation by Building a Calorie Counter - Step 22

Tell us what’s happening: what wrong in these code i dont understand

Your code so far

function cleanInputString(str) {
  const strArray = str.split('');
  const cleanStrArray = [];

 for (let i = 0; i < strArray.length; i++) {
    if (!["+", "-", " "].includes()) {
      // If it is not, push it to the cleanStrArray
      cleanStrArray.push();
    }
  }
 

}

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 22

This conditional statement isn’t checking anything:

It’s saying “if the array ["+", "-", " "] doesn’t include” … doesn’t include what? You’ll need to include something inside the parentheses to compare against the array.

You are also not pushing anything to cleanStrArray:

Again, you’ll need to include something inside the parentheses to push to the array.

Finally, I think your code will only pass once you’ve also removed the comment line (though this is an issue with the tests, as comments shouldn’t really interfere with the tests).

2 Likes

i removed comment line and also ! mark from if statement from line then what happen with again

1 Like

Could you share your updated code please?
You can use the Preformatted Text tool (</> icon or CTRL+e) to create two sets of triple backticks. Post your code between these so that it displays correctly on the forum.

1 Like

Just includes string array with i variable also push same array inside if condition.

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

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