Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 90 - 2632_CodeMind
P. 90

    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.
                     Step 11:  Select return block from the Functions category the drag and drop it below splash block.
                     Step 12:  Select Volume from variables category, then drag and drop in the return block as shown.

                                                                                           Advanced MakeCode Arcade    89

| 85 86 87 88 89 90 91 92 93 94 95 |