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