Search and Replace

I know my code is not the cleanest, but I ran the code on other platforms plus the tests and they seem to be working. someone tell me where I am going wrong

   **Your code so far**

function myReplace(str, before, after) {
let  newStr = str.split(' ')
const indx = newStr.indexOf(before)
const chnge = after.toLowerCase()
newStr.splice(indx, 1, chnge)

let final = newStr.join(' ')

return final

console.log(myReplace("He is Sleeping on the couch", "Sleeping", "sitting"));

   **Your browser information:**

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

Challenge: Search and Replace

Link to the challenge:

your output is

He is sitting on the couch

it needs to be

He is Sitting on the couch

you need to change the word but preserve the case

1 Like