Intermediate Algorithm Scripting - Search and Replace

Hi everyone. I want you to check my code please and tell me where is the wrong.

function myReplace(str, before, after) {

  if (/^[A-Z]/.test(before)){
    after = after.slice(0,1).toUpperCase() + after.slice(1)
  } 
  
  if(/^[A-Z]/.test(after)){
    before = before.slice(0,1).toUpperCase() + before.slice(1)
  }
  
  return str.replace(before, after)
}

console.log(myReplace("I think we should look up there", "up", "Down"))

Please post a link to the Step.

Can you talk about how you’re stuck? That helps us help you. Thank you

What happens when you run it, what’s it supposed to do?

Is there an error?

Is there unexpected output?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.