Replacing It All explainer


The aim of this puzzle: Use the recursive updateAllNames function to replace all the typos.

Walkthrough of the solution: Running a recursive function is just like calling any other function. You use the function name and put arguments (input values) in the parentheses. The updateAllNames function needs 3 input values:

  • The main string that is being searched and edited

  • The oldPart which is a string that will be replaced in the main string

  • The newPart which is a string that will take the place of the oldPart inside the main string

In this puzzle, the main string is the travelDocument. The oldPart is the typo: 'grasshoper' with 1 ‘p’. And the newPart is the correctly spelled version: 'grasshopper'. If you look inside the function definition, you’ll see the command: string.replace(oldPart, newPart). This makes sense for the arguments we gave it: travelDocument.replace('grasshoper', 'grasshopper').

The function call will return the updated travelDocument, but you’ll need to put it inside of a console.log() to see the new value.

Sample code solution:

(Tap below to reveal)

function updateAllNames(string, oldPart, newPart) {
  if (string.includes(oldPart) === false) {
    return string;
  string = string.replace(oldPart, newPart);
  return updateAllNames(string, oldPart, newPart);

console.log(updateAllNames(travelDocument, 'grasshoper', 'grasshopper'));

JavaScript Concepts: Calling Functions, Code Block (function, if statement), console.log(), Recursion, .replace()


I dd exactly this but it still didn’t work


Could you post a screenshot of your code?



I have the same problem


As an FYI, should you have the correct solution and you are still not able to get to the next puzzle, try clearing the cache of the app then reset the puzzle and insert the solution again.

Doing this I was able to proceed further.


I have the same problem. Can’t get to the next puzzle with the right code.


Could you post a screenshot of your code here?




Just a very small but important thing: there is an extra space at the end of the 'grasshopper' string.

Notice how where the closing quote mark is:
'grasshopper '



Thanks Frankie. It went like yesterday!