I am having an issue on this problem where I cant pass all the tests at once. If I change the globalTitle variable to the various quotes each of those tests will pass individually, however they wont all pass at once. Anyone know whats up??
/*
globalTitle -> mutableTitle -> noSpaceBeginning -> noSpaceMiddle -> frankenVar
*/
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title){
//Change globalTile to a mutable variable
let mutableTitle = "";
for (let i = 0; i < globalTitle.length; i++){
mutableTitle += globalTitle[i];
}
//Regex to remove spaces at the beginning
let beginningRegex = /^\s/;
let noBeginningSpace = "";
let beginningTest = beginningRegex.test(mutableTitle);
if (beginningTest) {
for (let j = 1; j < mutableTitle.length; j++){
noBeginningSpace += mutableTitle[j];
}
}else {
for (let i = 0; i < globalTitle.length; i++){
noBeginningSpace += mutableTitle[i];
}
}
//Regex to remove consecutive spaces in middle
let midRegex = /\s\s/;
var noSpaceMiddle = "";
let midTest = midRegex.test(noBeginningSpace);
if (midTest) {
for (let i = 0; i < noBeginningSpace.length; i++) {
if (noBeginningSpace[i] === " " && noBeginningSpace[i+1] === " "){
var myIndex = i;
}
}
for (let j = 0; j < noBeginningSpace.length; j++){
if (j === myIndex){
j++;
}
noSpaceMiddle += noBeginningSpace[j];
}
}else{
for (let i = 0; i < noBeginningSpace.length; i++){
noSpaceMiddle += noBeginningSpace[i];
}
}
//Convert string to no spaces, lowercase, and connected by "-"
let frankenVar = noSpaceMiddle.split(" ").join("-").toLowerCase();
console.log(frankenVar);
return frankenVar;
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"