Ntermediate Algorithm Scripting: Search and Replace 1

Tell us what’s happening:
cant identify the problem

Your code so far

       function myReplace(str, before, after) {
  var index= str.indexOf(before);
  if (str[index] === str[index].toUpperCase()) {
  after= after.charAt(0).toUpperCase().afterslice(1);
  } else {
    after = after.charAt(0).toLowerCase() + after.slice(1);

  }
  str=str.replace(before,after);

 return str;
}

function myReplace(str, before, after) {
 var index= str.indexOf(before);
 if (str[index] === str[index].toUpperCase()) {
 after= after.charAt(0).toUpperCase().afterslice(1);
 } else {
   after = after.charAt(0).toLowerCase() + after.slice(1);

 }
 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 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36.

Challenge: Search and Replace

Link to the challenge:

I added the function from the failed test in the editor, and now I see this:

TypeError: after.charAt(...).toUpperCase(...).afterslice is not a function

check that line for any error

Thanks great community

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.