Learn Form Validation by Building a Calorie Counter - Step 23

Tell us what’s happening: is these code wrong or right

Your code so far

function cleanInputString(str) {
const strArray = str.split(‘’);
const cleanStrArray = ;
const regex = /[^+-\s]/g;

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 (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 23

i can’t understand anything please try to make a better post

You should remove the cleanStrArray variable.
function cleanInputString(str) {
const strArray = str.split(‘’);
const cleanStrArray = ;
const regex = /[^±\s]/g;

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

bro use backticks than copy and paste your code . Use 6 backtick and in between them put your code like this.

function cleanInputString(str) {
  const strArray = str.split('');
  const cleanStrArray = [];
  const regex = /[^±\s]/g;

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

Happy coding

where i cant understand

You should remove the cleanStrArray variable.

Hello,
I was having the same issue.
The instructions say to replace the code within the function with the example given.

The solution is as follows:
const regex = /hello/;

I hope this helped.

Follow as the instruction says. Remove everything inside the function, and declare the regex variable and assign the value of ‘hello’.

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