Hello
I’ve written a very basic answer for the ‘Search and Replace’ exercise and it returns the correct answers, please see the code below. However it is not being accepted as a correct answer.
Could anyone tell me why that it the case?
Any help would be appreciated
var newStr = [];
function myReplace(str, before, after) {
if(before[0] === before[0].toUpperCase()){
var capAfter = after.replace(after[0], after[0].toUpperCase());
toUpperCase(str, before, capAfter);
} else {
toUpperCase(str, before, after);
}
function toUpperCase(x, y, z){
var split = x.split(' ');
for(var i = 0; i < split.length; i++){
newStr.push(split[i].replace(y, z));
}
}
return newStr.join(" ");
}
myReplace("Let us go to the store", "store", "mall");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
.
Link to the challenge: