Converting to spinal tap is not working! Help!

Hello! I have a little problem with the spinal tap challenge. In this I try to convert all the underscores to spaces for further parsing, but it treats the underscore as a separate character (and puts dashes around it.) Does anyone know what’s going on? Thanks!

Oh, and here’s my code.

    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
};

function isUpperCase(strng) {
  return strng == strng.toUpperCase();
}

function removeSpaces(arr) {
  var newArr = [];
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] !== " ") {
      newArr.push(arr[i]);
    }
    
  }
  return newArr;
}

function replaceChars(replacer, replacee) {
    var newString = "";
    for (var i = 0; i < replacee.length; i++) {
      if (replacee[i] == replacer) {
          newString += " ";
          console.log(replacee[i]);
      } else {
        newString += replacee[i].toLowerCase();  
      }
    }
  return replacee;
  
}

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  var replaced1 = replaceChars("_", str);
  console.log(replaced1);
  var replaced2 = replaceChars("-", replaced1);
  var chararray = removeSpaces(replaced2.split(""));
  
  var words = [""];
  var currentWordIndex = 0;
  chararray[0] = chararray[0].toLowerCase();
  for (var i = 0; i < chararray.length; i++) {
    if (isUpperCase(chararray[i])) {
      currentWordIndex++;
      words.push("");
      words[currentWordIndex] += chararray[i].toLowerCase();
    } else {
      words[currentWordIndex] += chararray[i];
    }
    
    
  }
  
  
  return words.join("-");
}

console.log(spinalCase('The_Andy_Griffith_Show'));
console.log("DONE DONE DONE");

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Your replaceChars function doesn’t work. JavaScript strings are immutable, meaning you can’t manipulate it directly, you can only make a new string.

Not sure why you wrote your won when JavaScript has a build it replace function for strings, the link to the MDN reference for the function is included in the challenge prompt.

Because you never replaced the underscore, your string doesn’t spit the way you want it, thus the dashes around the underscore.

OK. Thanks! I learned the part about the immutable strings when I did some more research, but thanks for the help!