Learn Form Validation by Building a Calorie Counter - Step 28

Tell us what’s happening:

Can Someone please me with Step 28!!
The instruction say: " Use your regex to replace all instances of + , - , and a space in str with an empty string. Return this value."

I have written the codes but, I am still stuck.

Your code so far

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.

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

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 28

1 Like

Hi, I think you used "replace method " twice,
if you want to do like this

const newRegex = str.replace(/+ -/g, " ");

You can make it like this

const newRegex = str.replace(/[+-\s]/g, "");   //[+-\s]/g  means + and - and white space

and the third row you typed should be like this:

return newRegex;

I am new one here, so I just discuss that this problem, but if you want a really correct answer, here is below:

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

Thank you so much. I am grateful for your Help!

1 Like

I am also New to Coding. I have the mindset and I am prepare to make the sacrifice. The beginning of Everything in my Life has not been Easy but, I proof to the People that Help me along the Way that I could do it and I make them proud as Well. I appreciate everyone of you Guys that are Helping me. I really Grateful!

2 Likes