Learn Form Validation by Building a Calorie Counter - Step 24

Tell us what’s happening:

I don’t know what is it that I am doing wrong, the code won’t pass.

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;
str = str.replace(regex, "");
return regex

}

// User Editable Region

Your browser information:

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

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 24

Why are you returning the regex from this function? What makes sense to return based on the function name?

I am still learning, please no need to say it like that. I managed to solve it though.

Hey,
great job on solving the problem. As a community, we are here to help each other. So don’t worry when you’re stuck or having issues with your code.
Happy coding :slightly_smiling_face:

1 Like

I’m sorry I offended you. I was trying to guide you to figure it out yourself (which you did!) rather than just giving you the answer.

thank you for wiling to help. I’d like to know if there is anywhere where I can learn further about this topic, I feel like even if I managed to solve it, I am still a little confused?

I get it. We’ve all been there. I think freeCodeCamp is a great place to learn about JavaScript because you get to learn by building small projects. But you’ll want a good reference to provide more examples when you need them. I suggest: JavaScript Reference. On the lefthand sidebar, if you scroll down under “References” you’ll see “Built-in Objects.” I use that a lot to find methods I can use for Array, String, Date, and other built-in objects.

Another way to just see if something works is to open up the Developer Tools in your browser (shift+ctrl+I), click the “Console” tab in the nav bar and just type in some code to test. And in your code here, you can add console.log() statements to see what a variable or condition is evaluating to at specific places in your code and look at the results in the “Console” tab.

That said, know that being confused is just part of the learning process. We all go through it. It’s frustrating. But you can do this! Just keep at it!

2 Likes

Thank you, it’ll be very helpful.