Build a Todo App using Local Storage - Step 65

Tell us what’s happening:

Hi, my code can’t pass the test, but I think it works. I found a post where somebody advised, that numbers should not be included, but it didn’t resolve my problem.

Your code so far

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

/* file: styles.css */

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

function removeSpecialChars(str) {
  const regex = /[^[a-z0-9]]*/ig;
  str = str.replace(regex, "");
  return str;
}
console.log(removeSpecialChars(`"chujDUIA''asd'"854237856'`))

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0

Challenge Information:

Build a Todo App using Local Storage - Step 65
https://www.freecodecamp.org/learn/full-stack-developer/workshop-todo-app/step-65

I tried to solve it with different method, but it fails to:

function removeSpecialChars(str) {
  const regex = /[a-z0-9]+/i;
  str = str.split("");
  str = str.filter((char) => regex.test(char))
  str = str.join("")
  return str;
}

I have just realized, I can go to the next step and peek the answer.

I should have not remove minus signs and whitespaces.

Therefore:

  const regex = /[^[a-z0-9\-\s]]*/ig;

I think a note would be useful.

that’s not a great way to solve it

Unless you want to earn a certificate but that doesn’t Help in any way in relation to skills and handling real world problems which would in turn count during interviews. You’ve to train your mind to think logically understand concepts and not just completing challenges

But my code was working. Okay, I should have added the \s to the regex. I didn’t test that, but I wouldn’t have tested the hyphen if the underscore and other special characters should be excluded.

Someone on the forum would have told me that. This way was quicker though, so I don’t think your remarks on my learning process are accurate this time.