Learn with tiles › 35
Returning a value
A function gives the value it calculated back to the place that called it.
1
The return tile gives the value made by the function back to the place that called it. Then you can put the function in a slot and use it like a value.
twice(4) returns 8. So Console.WriteLine(twice(4)) writes 8.
To do Change the value passed so that 20 appears.
Loading tiles…
2
This time you fix the inside of the function. The function triple should return three times the number it receives, but right now it returns the number as it is.
To do Fix the inside of the function so that 15 and 21 appear, one per line.
Loading tiles…
3
When a function meets "return", it ends right there. It does not run the tiles below.
The function bigger should return the bigger of two numbers. If the first is bigger, it returns the first and ends. If not, it goes on down to the bottom.
To do Fix the "return" at the bottom so that the bigger of the two numbers appears. For 3 9 it is 9.
Loading tiles…