Learn Form Validation by Building a Calorie Counter - Step 22

Tell us what’s happening:

step 22, I don’t know what is wrong.

### Your code so far

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]);
}
}
}

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.

Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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

:balloon:Hello @hungozada! Welcome to the forum!

I just tried a similar version of your code as below, which also will not pass the tests, but logs the expected output IMHO.

function cleanInputStrings(str) {
  const strArray = str.split("");
  const cleanStrArray = [];

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

cleanInputStrings("123 +9-8");  // ["1","2","3","9","8"]

Might be a candidate for a PR?

There appear to be error in the test, if you remove semicolon from the following line, test will pass.

cleanStrArray.push(strArray[i])
2 Likes

Thank you sanity, you are right.

1 Like

An issue has been created to update the tests

2 Likes