I feel I did it right, but it still won’t work.
Try taking out the spaces in the strings:
–Frankie
Can you explain use of code return, in if block code, return string is it mean to return to string on argument of updateAllName() function or to updated string?
Trims
return
is used inside of a Function Definition to end the function and send an output value.
In the updateAllNames
function, there are 2 return
statements, but only 1 of them will run when the function is called. Notice the 1st return
is inside of an If Statement, that means it will only run if the test is true. If it’s false, then the 2nd return
will run.
The return string
says, “This function call is done. The final value of this function call is the string
value from the beginning of this function call.”
The return updateAllNames(string, oldPart, newPart)
says, “This function call is done. The final value of this function call will be whatever comes out of this other function call.” It just happens that the function it is going to call is itself.
You can picture each function call as a robot: you can turn it on (call it), give it some extra information (arguments), it will do its job predictably, and have a final output (return value). For the updateAllNames
robot, when it gets to the part where it needs to run another updateAllNames
robot, it creates fresh new updateAllNames
robot, identical to itself, except this one gets different extra information (arguments).
–Frankie
Do you mean in IF statement when string.include(oldPart) == false the return string not executed than jump to updated string than cek it again with return updateAllName() function so when If statement found string not include oldpart it’s equal true than return string executed and code stop, is it like that?
Sorry i just an idiot
The If Statement test is string.includes(oldPart) === false
. This is checking if the string is correct. If it is, then the function is finished and it outputs the string. If it isn’t correct, then it replaces 1 typo, and then runs the function again to check if the string is now correct.
–Frankie
I understand now, it’s boolean
Thanks alot
I have the same problem
You’ll need to use the travelDocument
variable rather than a string that says, 'traveldocument'
. The travelDocument
variable is storing a long string that will look something like:
'Hello grasshoperTicket! You will be going to the Maldives. Your travel code is: "no1grasshoper" Enjoy your trip grasshoper!'
Delete the orange 'traveldocument'
string and insert the grey travelDocument
variable in its place.
–Frankie
Not cool, I have the following code and It’s wrong…
The only part of the code I changed was adding a last console.log of updateAllNames
console.log(updateAllNames(travelDocument, ‘grasshopper’, ‘grasshopper’));
Hey there,
The updateAllNames
function replaces one string with another. In this case, we want to replace the misspelled 'grasshoper'
(1 'p'
) with the correct spelling 'grasshopper'
(2 'p'
s).
It looks like you’ve got the correct spelling in both. Try changing
console.log(updateAllNames(travelDocument, ‘grasshopper’, ‘grasshopper’));
to
console.log(updateAllNames(travelDocument, ‘grasshoper’, ‘grasshopper’));
Hope this helps!
-Ben
Yes this worked, man do I feel dumb now! Thank you for clearing this up.
I have the corect code and i checked for accidental spaces and it still says I’m doing something wrong
Hey there,
It looks like there’s an extra whitespace after the last r in 'grasshoper'
. Everything else looks good though! Just fix that string and the puzzle should complete.
Ben
Hey there, in the last console.log()
at the bottom of the code, change the 1st 'grasshopper'
to 'grasshoper'
.
We want to find the incorrect spelling and replace it with the correct spelling, but you have grasshopper spelled correctly both times.
Hope this helps!
Ben
IT won’t WORK SOMEONE PLS HALP MEHHH.
Hey there, try posting a screenshot of your code.
I don’t really understand this code. Why are oldPart and newPart? Are they like default function argument?
PS: Nevermind. I understand it.