How does one compare the cases of letters? I don’t know how to express it in the ‘before.charAt(0) === after.charAt(0)’ part. I know it is only comparing the letters right now.
function myReplace(str, before, after) {
var newStr = '';
var arr = str.split(' ');
var afterNew = after.replace(after.charAt(0),after.charAt(0).toUpperCase());
if (before.charAt(0) === after.charAt(0)) {
newStr = str.replace(before, afterNew);
} else {
newStr = str.replace(before, after);
}
console.log(newStr);
return newStr;
}
myReplace("Let us go to the store", "store", "mall");
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace/