Tell us what’s happening:
I think I have actually done what the lab required and returned it properly but it throws an undefined error and I can’t tell what exactly is undefined
Your code so far
function myReplace(str,oldWord,newWord){
if(/^[A-Z]/.test(oldWord)){
console.log("yes");
newWord = newWord[0].toUpperCase()+newWord.slice[1];
}else{
newWord = newWord[0].toLowerCase() + newWord.slice[1];
}
return str.replace(oldWord, newWord);
}
console.log(myReplace("Let us go to the store", "store", "mall"));
console.log(myReplace("He is Sleeping on the couch", "Sleeping", "sitting"));
console.log(myReplace("I think we should look up there", "up", "Down"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Challenge Information:
Build a Smart Word Replacement Function - Build a Smart Word Replacement Function