7. Reusable Code with Functions
Learn Reusable Code with Functions through beginner-friendly explanations, working GOCO examples, and their expected output.
7.1 What is a Function?
A function is a named block of code you can use over and over. You give it an input, and it does the job. Notice that a function must close with '}.' at the end.
goco
Function sayHello(Sentence name) {Displaynl("Hello there, " + name + "!").}.// Using the functionsayHello("Tom").sayHello("Jerry").
7.2 Getting Answers Back
Some functions do not do actions. They find answers and give them back to you using Return. You have to tell it what kind of box it Returns.
goco
Function getDouble(Number a) {Return a * 2.} Returns Number.Number answer = getDouble(5).Displaynl(answer).