Intermediate Algorithm Scripting - Search and Replace

Tell us what’s happening:
Describe your issue in detail here.
I don t get why it doesn t pass when i try all the tests it works but when i press space + enter it gives me errors and only 2 of the tests passes

Your code so far

function myReplace(str, before, after) {
   let some = str.split(" ");
   for(let i = 0; some.length > i; i++) {
     if (some[i] === before) {
        some[i] = after;
     }
   }
  return some.join(" ");
}

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/113.0.0.0 Safari/537.36 OPR/99.0.0.0

Challenge: Intermediate Algorithm Scripting - Search and Replace

Link to the challenge:

Note: Preserve the case of the first character in the original word when you are replacing it. For example if you mean to replace the word Book with the word dog, it should be replaced as Dog

Look at the output of your console log. The first letter of “up” is lowercase, so when you replace it with “Down” you must convert the “D” to lowercase.

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