Struggling with Spinal Case Algorithmic Challenge

Tell us what’s happening:
Hi. I’ve been working on this challenge for a while now. I had some trouble learning regular expressions so had to look for other online tutorials. I think I’m finally getting it, and this challenge seems like it should be done, but two of the tests are still coming back with errors. I can’t seem to figure out why. Can anyone help here? Thanks.

  **Your code so far**

function spinalCase(str) {
let regex = /\s+|_+/g;
let newStr = str.replace(regex, '-');
newStr = newStr.replace(/([a-z])([A-Z])/g, "$1 $2");
newStr = newStr.toLowerCase();
console.log(newStr);
return newStr;
}

spinalCase('This Is Spinal Tap');
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4693.0 Safari/537.36 Edg/98.0.1074.0

Challenge: Spinal Tap Case

Link to the challenge:

Try swapping the order of your two replace statements.

newStr.replace(/([a-z])([A-Z])/g, "$1 $2");

Is introducing spaces into the string after you have replaced spaces with “-”.

1 Like

Thanks. Not sure how I missed that.

I’m glad I could help. Happy coding!

1 Like

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