Tell us what’s happening:
i don’t understand why my for loop doesn’t work, can anyone explain
Your code so far
function spinalCase(str) {
// "It's such a fine line between stupid, and clever."
// --David St. Hubbins
str = str.replace(/\s/g,"-");
str = str.replace(/_/g,"-");
for (i=1;i< str.length;i++) // Have no idea why this for loop doesn't work...
{
if (90>=str.charCodeAt(i)>=65 && str.charAt(i)===str.charAt(i).toUpperCase() && str.charAt(i-1) !== "-")
{
str = [str.slice(0, i), "-",str.slice(i)].join('');
}
}
return str.toLowerCase();
}
spinalCase('AllThe-small Things');
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/spinal-tap-case