Try taking out the spaces in the strings:
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?
return is used inside of a Function Definition to end the function and send an output value.
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.
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.”
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).
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.
I understand now, it’s boolean
You’ll need to use the
travelDocument variable rather than a string that says,
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.