Spinal Tap Algorithm toLowerCase is not working

Tell us what’s happening:
I’ve been working on the spinal tap algorithm and I got all of the tests to pass except “spinalCase(“thisIsSpinalTap”).” So, I looked at the hint and got the reg ex for searching out capital letters. I then only saw that my toLowerCase was in the wrong spot by placing it before the regex test, so I moved it down as in the code shown below. From my understanding, it is placed on a string and should return the same string with only lowercase letters, but this is not happening. Can someone tell me why this doesn’t work?
I’m tempted to go with the last solution. I uses the toLowerCase and is so easy to use that I’ve already got it memorized based on it’s simplicity. However, I feel like this solution should work with some small change. I’ve tried several and searched a bit but come up with nothing.
Thanks for any help.
Your code so far


function spinalCase(str) {
var newStr = str;
const newArray = newStr.split(/\s|_|(?=[A-Z])/);
console.log(newArray);
newStr = newArray.join("-");
newStr.toLowerCase();
console.log(newStr);
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
return newStr;
}
spinalCase('thisIsSpinalTap'); 

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Spinal Tap Case

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/spinal-tap-case

Thank you! I assigned it to a variable attached to the join method and it works. I also get, unless incorrect, that the third solution works because it is assigned to the functions return value.

1 Like