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()
Additional Code (hidden code that runs before the puzzle’s code):

let travelDocument = 
`Hello grasshoper${pickRandom(['','Travel','Passport','Ticket','Plans','Vacation','Holiday','Trip'])}!
You will be going to ${pickRandom(['New Zealand','Cyprus','the Maldives','Oahu','Palawan','Bali','Maui'])}.
Your travel code is: "${pickRandom(['grasshoper8ugs','im1grasshoper','no1grasshoper'])}"
Enjoy your trip grasshoper!`;

I dd exactly this but it still didn’t work


Could you post a screenshot of your code?



I have the same problem

1 Like

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.

1 Like

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

1 Like

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 '


1 Like

Thanks Frankie. It went like yesterday!


Where can I find the full code, so I understand it better

I dont have a .log or .return in my keys and it womt let me type it in. How do i get .log for console

There should be a .log() button if you scroll to the right in the keyboard. There isn’t a .return key, but the 2nd key should be return, without the dot.


I cannot do this thing. I will send a screenshot. Can you please help me do this.

At the bottom of your code, the updateAllNames() function takes 3 arguments: the document, the misspelled word, and the correct spelling. You have the correct spelling twice. Change the 1st 'grasshopper' into 'grasshoper' by removing 1 letter 'p'.


Thanks for the help. Is grasshopper good to children of 13 years.

1 Like

I have some problem,
Some body help.

yeah, i tried to restart my device and stuff, but there is still not .log() or return.

I rebooted my device and now i have the keys i need but now i am confused on what code i entered wrong Screenshot_20190211-151817_Grasshopper|281x500

I’m not able to see the file you uploaded. But to solve this puzzle, there’s only a few things to do:

  • Reset, to make sure none of the starter code was changed
  • The code you add will go at the very bottom
  • Add console.log()
  • Inside the parentheses of .log(), add updateAllNames()
  • Inside the parentheses of updateAllNames(), you will add 3 arguments
  • The order of the arguments are:
    • The travelDocument variable
    • The 'grasshoper' string, with 1 'p', no capitals or spaces
    • The 'grasshopper' string, with 2 'p's, no capitals or spaces