Created a function that is suppose to remove all of the vowels in a given string that is passed as an argument for the function

And yet, everytime I run this code, I get this error:TypeError: str.remove is not a function

I don’t see why this is an error since remove() is a javscript function

Here is the link to my code:https://codepen.io/noblegas/pen/eYmNwBO

1 Like

Would my for loop still work? I want to actually stick to the longer approach first.

If I did use the replace method for my for loop, could I replace my vowels in my string with empty space?

I updated my code and applied your suggestion but now I get this error:

“SyntaxError: invalid regular expression flag e”

Here is the link with my updated code.

Updated my code again , but I don’t get an error ,It just prints the string that I originally passed in my function as an argument but doesn’t removed the vowels.https://codepen.io/noblegas/pen/eYmNwBO

New NEW update: Now I am getting THIS error as it is not removing ALL of my vowels in my string.

“Cllege park sucks”

The specific issue is that the regular expression matches only the first vowel. To solve this problem, you need to learn about flags.

Once you fix this specific issue however, you might realize that the for loop is unnecessary. The string is being re-assigned at every iteration, but it is enough to run the regular expression only once.

Let me know if it helps. I’ll just like to add that the freeCodeCamp curriculum has an entire section devoted to regular expressions, and a one challenge dedicated to this very topic. You will definitely find those resources much more helpful than I could ever be.

1 Like

Can you describe in simple english,
what every line of your code should do?

E.g. why do you use a for loop?

My solution worked and I took your advice:

"function disemvowel(str) {
// for (var x = 0; x < str.length; x++)
// {
// // var c = str.charAt(x);

// // if(c=='a' ||c=='e'||c=='i'||c=='o'||c=='u'){
// //     str.remove(c);

// // }



// }
var regex= /a|e|i|o|u/gi;
var newstr=str.replace(regex, "");
console.log(newstr)

}
console.log(disemvowel(“College park sucks”));"

output of the expression:
“Cllg prk scks”

Thank you so much!

1 Like

Glad you found it helpful @noblegas87 :+1: