Tell us what’s happening:
I believe this is working mostly, but I am stumped trying to figure out how the toUpperCase should work. The toLowerCase works, so I feel close. I am trying to not look at hints, but rather dig around for insight. I might try a completely different approach soon. But I feel so close that I might be making a typo?
**Your code so far**
function myReplace(str, before, after) {
var strArr = str.split(" ");
if (before.charAt(0) === /[A-Z]/) {
strArr.splice(strArr.indexOf(before), 1, after.charAt(0).toUpperCase() + after.slice(1));
} else if(before.charAt(0) != /[A-Z]/) {
strArr.splice(strArr.indexOf(before), 1, after.charAt(0).toLowerCase() + after.slice(1));
}
console.log(strArr.join(" "));
return strArr.join(" ");
}
console.log(myReplace("I think we should look up there", "up", "Down"))
console.log(myReplace("He is Sleeping on the couch", "Sleeping", "sitting"))
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Challenge: Search and Replace
Link to the challenge: