Intermediate Algorithm Scripting - Search and Replace

Tell us what’s happening:
Describe your issue in detail here.

Your code so far

function myReplace(str, before, after) {
  let newStr = str.split(" ");
  let indexToReplace = newStr.indexOf(before);
  let firstLetter = "";

  if (before.charAt(0) === before.charAt(0).toUpperCase()) {
    firstLetter = after.charAt(0).toUpperCase();
    after = after.replace(after.charAt(0), firstLetter);
  } else {
    firstLetter = after.charAt(0).toLowerCase();
    after = after.replace(after.charAt(0), firstLetter);
  }

  newStr.splice(indexToReplace, 1, after);

  return newStr.join(" ");
}

console.log(myReplace("I think we should look up there", "up", "Down"));
console.log(myReplace("He is Sleeping on the couch", "Sleeping", "sitting"));


**Your browser information:**

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78</code>

**Challenge:**  Intermediate Algorithm Scripting - Search and Replace

**Link to the challenge:**
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace

Welcome to the forum!
Your code passes the tests on my end. What issues do you have with this code?