Wont change charecter case

my code is supposed to take a word (before) and replace it with another word(after) inside of a string(str). my code replaces the words easily however i am having trouble getting the replaced word to have the same case as the original.

function myReplace(str, before, after) {

if(before[0].toUpperCase() === before[0]){
} else {
str = str.replace(before, after);
return str

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.72

Challenge: Search and Replace

Link to the challenge:

Look up the documentation on toUpperCase and what it returns, and if strings are mutable.

someString.toUpperCase() does not change someString.