Hello everyone. I have been trying the following code so far to solve this challenge:
let hello = " Hello, World! ";
let wsRegex = /^\s*|\s*$/; // Change this line
let result = hello.replace(wsRegex,""); // Change this line
I have tried it also on jsbin.com and the result is “Hello, World!”, as expected. But on freeCodeCamp I pass two out of the three tests but the third says:
result should equal to “Hello, World!”. What am I doing wrong?
Thank you in advance.
When you have problem with a challenge to provide a link to it will improve the pertinence of the answers
Anyway, you’re testing for spaces at the start OR spaces at the end ^^
If you want the regex not to match just the first occurrence ( the spaces at the start i guess) you should use the g flag ^^
The | is an OR operator
The g flag is needed to match all the spaces that are at the beginning OR at the end. Otherwise it would match only the first part of the regex, and the second part only if the first part doesn’t match anything