What's the problem with the code

Tell us what’s happening:

What’s the problem with my code.
I have noticed that when I console.log(index), I get -1 as output. But index is equal to 4 according to the sentence in the last line

Your code so far


function myReplace(str, before, after) {
str = str.split(' ')
let index = str.indexOf(before);
if(before[0] == before[0].toUpperCase()){
 after = after[0].toUpperCase() + after.slice(1)
}
str.splice(index, 1, after)

return str.join(' ');
}

console.log(myReplace("A quick brown fox jumped over the lazy dog", "Jumped", "leaped"));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36.

Challenge: Search and Replace

Link to the challenge:

check if the case of the before is same as the statement.

I didnt understand. Can you explain in more detail

before checking the indexof(before), convert the before-string to lowercase.

jumping != Jumping

Thanks… but can you tell what was the problem

jumped = 1st letter is small case
Jumped = 1st letter is Upper case.

the indexOf function gives -1 as output when the EXACT value is not available in the array.