Intermediate Algorithm Scripting - Search and Replace

Tell us what’s happening:
My code is working in Visual Studio, why not here?

Your code so far

function myReplace(str, before, after) {

  if (before.charAt(0) === before.charAt(0).toUpperCase()) {
    after = after.charAt(0).toUpperCase() + after.slice(1);
  } else if (before.charAt(0) === before.charAt(0).toLowerCase()) {
    after = after.charAt(0).toLowerCase() + after.slice(1);
  }

  let newString = str.replace(before, after);
  console.log(newString);

}

myReplace("My name is kurt Opsomer", "kurt", "Peter");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Challenge: Intermediate Algorithm Scripting - Search and Replace

Link to the challenge:

Its looking at the return value. What are your returning from that function?

That is what is asked in the task… If I run this JavaScript code in Visual Studio Code, I get the good (corrected) string:

My name is peter Opsomer

You were asked to use return, not console.log

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