Learn localStorage by Building a Todo App - Step 67

Tell us what’s happening:

I am confused on why it keeps saying that I am not removing the quote and underscore.

I even test it, and it work.

Your code so far

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

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

function removeSpecialChars(a){
  console.log(a.replace(/["'_]/g,""))
  
}

removeSpecialChars(`Hello"'_`)



// User Editable Region
/* file: styles.css */

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 Edg/132.0.0.0

Challenge Information:

Learn localStorage by Building a Todo App - Step 67

*EDIT: I apologize. I was wrong your regex does pass. I should have ran the code you provided(recreate the problem) but I assumed it was wrong .

Hello and Welcome!

The instructions:

“In order to fix this, we need to create a function called removeSpecialChars that takes a string as input and removes all special characters.”

The Issue:

/["'_]/g does not look for all special characters.

The Why:

In addition to this specific case you are also writing code for as many use cases as possible, this includes all the other special characters. It makes sense because writing code to solve a bag of problems instead one specific problem will save the dev(you) time in the future.

Possible Solution Help:

You could try to look for and replace the negation of every number, upper case, lower case, and hyphen. Be sure for account for whitespace, there is a static method you can use for that.

what is your function returning?

oops, I forgot that function need something to return.

Oh ok, I think I have a clearer view on what to do next. Thanks for the help!

I’m confused by your edit. The poster’s code didn’t pass. Ca you explain your edit.

The poster found some of your answer helpful though see below.

@a1legalfreelance,
While the code fails, the regex of the original code works and passes the test when everything else is correct.

I asumed the the regex was wrong instead of what I should of done, which is analyze and test the regex. The poster’s code itself did not pass because of the console log instead of return of the code.

There are just a lot of ways to do the same thing. Although the regex I was suggesting does capture more use cases @cybordgeneral 's regex would still pass the when the rest of the code is is correct.

I hope that answers your question.

1 Like