Learn Form Validation by Building a Calorie Counter - Step 24

Tell us what’s happening: Pls help :disappointed_face:

Im not sure where my code is messing up here.. this is the error msg i get: 1. Your cleanInputString should call the replace method of str.
2. You should pass regex as the first argument to replace.
3. You should pass “” as the second argument to replace.
4. Your cleanInputString function should directly return the result of your replace method.

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

function cleanInputString(str) {
  const regex = /[+-\s]/g;
  cleanInputString.replace(regex, "");
  return cleanInputString();
}

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 24

Hi @90sFloppydisk

Use your regex to replace all instances of + , - , and a space in str with an empty string. Return this value.

You are not asked to return the function.
Please read the instructions carefully, take not of the highlighted parts.

Happy coding

Ive tried many different combinations including without returning the function.. at this point im just stuck

The first arrows points to the function, the second points to returning the same function as a function call. So that is not need for this step.

Try adding a console.log() below the function, and call the function with an argument.

Hi, I tried doing this as you said but im still receiving error msg :disappointed_face:

What’s the error message in the console and your current code?

function cleanInputString(str) {
const regex = /[±\s]/g;
cleanInputString.replace(regex, “”);
}
console.log(cleanInputString()); ------not sure what to put in as the argument, when i add (regex, “”) that doesnt work either

error // 1. Your

cleanInputString

should call the

replace

method of

str

. 2. You should pass

regex

as the first argument to

replace

. 3. You should pass

""

as the second argument to

replace

. 4. Your

cleanInputString

function should directly return the result of your

replace

method.

The message in the console is:

Uncaught TypeError: cleanInputString.replace is not a function

So that means that the cleanInputString part of the code in the the body of the function is not quite right.

In your own words, what does the last two sentences of the instructions ask you to do?

Also, use the following method to post code to the forum:

  1. On a separate line type three back ticks.
  2. On a separate line paste your code.
  3. On the last line type three back ticks. Here is a single back tick `

its telling me to use regex as the first argument in (str) and then to use “” as the second argument. im not sure where to use .replace() since theres only cleanInputString(str) function and regex

The .replace() method and arguments is correct.
On what do you want to apply the replace method on?

i want to apply replace onto the value of regex >> /[±\s]/g; like it says but thats where Im stuck im not sure what to put it on becuase regex.replace() doesnt make sense and the only other thing there is the function itself which also isnt working

Can you list the highlighted keywords from the last two sentences?

console.log is useful to test your code, if you reread the recommendation, it was to use console.log to wrap a call to your function so you could see the output of the function in the console, not to use it inside the function

1 Like

thanks, yes im aware.. I suppose since I kept getting a perpetual error msg on the console anyway it wasnt going to help much in this instance since it didnt lead me toward using return anyway.. trial and error did