I am stuck on this coding challenge Spinal Tap Case from freeCodeCamp. Essentially I don't know how to get the last check to execute.
This is the last check:
spinalCase("AllThe-small Things") should return "all-the-small-things"
And this is my code:
function spinalCase(str) {
var outputString,
newstr,
pattern1 = new RegExp(/[_\s]/, 'g'),
pattern2 = new RegExp(/(?=[A-Z])/, 'g'),
stringTest1 = pattern1.test(str),
stringTest2 = pattern2.test(str);
if(stringTest1) {
outputString = str.replace(pattern1, '-');
newstr = outputString.toLowerCase();
} else if(stringTest2) {
str.split(/(?=[A-Z])/).join(' ');
outputString = str.replace(pattern2, '-');
newstr = outputString.toLowerCase();
} else if (stringTest1 && stringTest2){
outputString = str.replace(pattern1, '-');
outputString = str.replace(pattern2, '-');
newstr = outputString.toLowerCase();
}
return newstr;
}
I do realize the last else if
condition should go first however I didn't get the syntax right.
Thanks in advance!