Learn Form Validation by Building a Calorie Counter - Step 22

Tell us what’s happening:

In step 22 despite following the instructions I have come to face an issue that it is not letting me pass despite making sure that my code compiles and returns the requested output.

Although it recommends me to recheck, but I did my due diligence and had tried my code on different platforms and as expected it performs the way as it is instructed.

Your code so far

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

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

The console response to my code.

// running tests
Your for loop should have an if statement.
Your for loop should use !["+", "-", " "].includes().
Your for loop should see if strArray[i] is found in ["+", "-", " "].
Your for loop should push strArray[i] to cleanStrArray.
// tests completed

My code on other console.

//test
console.log(cleanInputString('badmanners+/'));
//output
[
  'b', 'a', 'd', 'm',
  'a', 'n', 'n', 'e',
  'r', 's', '/'
]

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 22

you are not following the instructions. Also includes accepts one single argment, not 3, so it’s not working for that reason

I’ve mistakenly put an older one.

function cleanInputString(str) {
  const strArray = str.split('');
  const cleanStrArray = [];
  
  for (let i = 0; i < strArray.length; i++) {
    if( !["+", "-", " "].includes(strArray[i])){
      cleanStrArray.push(strArray[i]);
    }

  }
/*  return cleanStrArray;
extra code to check on other compilers
*/
}

but it still doesn’t work.

remove this space, and the tests will pass

1 Like

Sorry for my mistake and thank you. It was a trifle, but I am glad for the assist and finally completing the task

1 Like

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