Tell us what’s happening:
Hi there kind fellows,
I have made a piece of code that works. However, it doesn’t pass the tests. Can anyone sort this out?
Your code so far
function myReplace(str, before, after) {
let splitstr = str.split(" ");
let index = splitstr.indexOf(before);
console.log(splitstr[index]);
if (splitstr[index].split("")[0] == splitstr[index].split("")[0].toUpperCase()) {
after = after.charAt(0).toUpperCase() + after.slice(1);
}
splitstr.splice(index, 1, after);
for (let ind = 0; ind < splitstr.length; ind++) {
splitstr[ind] = splitstr[ind] + " ";
}
let ret = ( splitstr.join(""));
console.log( ret);
}
myReplace("Let us go to the store", "store", "mall");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
.
Challenge: Search and Replace
Link to the challenge: