Page 52 - Touchcode_C7_Flipbook
P. 52

Step 13: Click on ‘Start the simulator’ to see the output:


























                       Well done, you have learned to calculate the area of a circle.



                  CAN FUNCTION RETURN A VALUE?
                  The main purpose of using functions is to get rid of the repetitive block of code. So, when

                  an operation is performed inside a function it gives back a value, which can be used later in
                  the program to get the results.

                                                                                                    Experiential Learning
                                                       Coding Task          07


                                                   Return values from functions

                   In this task, you will learn to calculate the square and cube of a number using function
                   then add the values and print the results generated from these two
                   functions.

                   To perform the task, follow these steps:

                   Step 1:  Visit the link: https://arcade.makecode.com/. Give the
                             name of  your  project as ‘Return  values  from functions’

                             and click on ‘Create’.

                   Step 2:  Create variables: Var1, Var2, Var3, Cube and Square.

                   Step 3:  Click on  ‘Function’,  select ‘Make  a Function’. Name the
                             function ‘Cube of a number’, Click on ‘Number’, and name
                             it as ‘num1’. Click on ‘Done’. Function ‘Cube of a number’,

                             will appear on workspace.



                   50     Touchcode-VII
   47   48   49   50   51   52   53   54   55   56   57