Search and Replace------Why this doesnt work?

Tell us what’s happening:
Hi i dont know why my code doesnt work.
Thanks

Your code so far

js

function myReplace(str, before, after) {
 let nevim = str.split(" ")
 let newArr = [];

  nevim.map((item, i, arr) => {
    if(item === before) {
      if(item[0] === item[0].toUpperCase()) {
        newArr.push(after[0].toUpperCase() +  
          after.slice(1))
      }else{
        newArr.push(after)
      }
    }else{
      newArr.push(item)
    }
  })

let final = newArr.join(" ")
console.log(final)
}
myReplace("Let us go to the store", "store", "mall");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36.

Challenge: Search and Replace

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/search-and-replace

do you know what your function returns?
you need to have your function return something before knowing which tests pass

second point, your use of map is atrocious. please study on it and use it as intended (would even make your code simpler) or change method

1 Like

Thank you so much!!! I am an idiot…