Search and replace 23

Tell us what’s happening:
y i am not getting

Your code so far

function myReplace(str, before, after) {
var index = str.indexOf(before);
if (str[index] === str[index].toUpperCase()){
  after = after.chatAt(0).toUpperCase() + 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36.

Challenge: Search and Replace

Link to the challenge:

2 things
First it is charAt(0) not chatAt(0)
If first letter is small of before and capital of the after word you need to make it small
Then it will pass the tests

1 Like