Lesson goal: Functions that return values

Previous: Introduction | Home | Next: Convert between Celsius and Fahrenheit

The last lesson showed you how functions can be used to perform the same job over and over again. Sometimes it is useful for a function to return some result back to the main programmed that called it. You can do this by putting a return statement as the last line in your function.

function name(input 1,input 2,...)
BODY
return(some-value)
end
Move the mouse over a dotted box for more information.

Take a look at the default code below (hit [Reload] on your browser to reset the page if needed). It defines a function called add3 that takes in three numbers and adds them together. It then returns their sum back to the main calling line in the program.

Now you try. Run and tweak the this code.

Type your code here:


See your results here: