Removing whitespace

I’ve got this error:

The value of the hello variable should not be changed.

where did i go wrong?

Your code so far


let hello = "   Hello, World!  ";
let wsRegex = /(^\s+)(.*\S)(\s+$)/g; // Change this line
let result = hello.replace(wsRegex, $2); // Change this line

Your browser information:

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

Challenge: Remove Whitespace from Start and End

Link to the challenge:

$2 should be a string '$2'

MDN: replace Specifying a string as a parameter

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.