Page 39 - Touchcode_C7_Flipbook
P. 39

3                                    FUN WITH FUNCTIONS












                         Learning Outcomes

                      Introduction                                          What Exactly are Functions?
                      How to Reduce Redundancy Using Functions?             Advantages of Using Functions

                      What are Different Function Parameters?                Can Function Return a Value?
                      What is an Event?




                 INTRODUCTION
                 Pattern is a series of repeated occurrences in some sort of a sequence. In the same way,
                 there is a pattern in code too. When you are programming, there are times when you want

                 the computer to repeat certain lines of code in sequence. If there is a block of code that you
                 need to repeat in different scenarios, you can use a function. Functions are blocks of code
                 that can be used repeatedly for similar scenarios. A real life analogy to a function would be
                 a function.

                 WHAT EXACTLY ARE FUNCTIONS?

                 Function is a block of code which is executed only when it is called and performs a single
                 specified action.


                                                                                                   Experiential Learning
                                                      Coding Task          01


                                         Calling a function which has no parameters

                  To perform the task, follow these steps:

                  Step 1:  Open MakeCode Arcade and create a new project, ‘Function with no parameter’.
                            Click on ‘Create’.


                  Step 2:  Click on ‘Advanced’, select ‘Functions’, and click on ‘Make
                            a Function...’. Click on ‘Done’. The function will appear.

                  Step 3:  You can rename the function,  by clicking  on
                            ‘doSomething’,  in  this  case we  have  renamed  the
                            function as ‘Touchcode-7’.



                                                                                           Fun with Functions    37
   34   35   36   37   38   39   40   41   42   43   44