This code gives the correct output when I review it using console.log but the challenge just refuses to accept this code.
link to the challenge : search and replace
function myReplace(str, before, after) {
let work=str.split(" ");
str="";
for (let i=0;i<work.length;i++)
{
if(work[i]==before)
{
if(before.charAt(0)==before.charAt(0).toUpperCase())
{
after=after.charAt(0).toUpperCase()+after.slice(1);
}
work[i]=after;
}
str=str+" "+work[i];
}
return str;
}
myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");