Page 75 - ThinkGPT_V2.1_C8_Flipbook
P. 75

Returning Value from a Function

                 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, which makes a function more useful.
                 Let us create a project that demonstrates the use of function block for calculating volume of a
                 cuboid using parameters and arguments and return block. Follow the given steps to make the project
                 in MakeCode Arcade:

                 Step 1   Create a new project.

                 Step 2    Select Make a function in the Functions category from the Blocks Palette and name it
                          VolumeofCuboid.

















                 Step 3    Name the function in the Edit Function dialog box and add three Number as 3 different
                          parameters.

                 Step 4   Click Done.

                 Step 5    Select Make a variable from the Variables category in the Blocks Palette and name it
                          Volume.

                 Step 6    Select set Volume to 0 block from the Variables category then drag and drop it in the
                          "function" block.

                 Step 7    Select two multiplication blocks from the Math Category then drag and drop them in the
                          set Volume to 0 block.

                 Step 8    Drag and drop three numbers from function block in the multiplication blocks as shown.













                 Step 9    Select a splash block from the Game category, then drag and drop it below set Volume to
                          0 block.

                 Step 10  Edit the slash block with Volume of cuboid is.



                                                                                Advanced MakeCode Arcade      73
   70   71   72   73   74   75   76   77   78   79   80