Page 68 - Touchcode_C7_Flipbook
P. 68

Experiential Learning
                                                       Coding Task            04



                                       To calculate the sum of the elements in an array

                   In this task, you will learn to calculate the sum of elements in an array in MakeCode Arcade.

                   To perform the task, follow these steps:

                   Step 1:  Open MakeCode Arcade and create a new project ‘Array’.

                   Step 2:  Create a variable, ‘arr’.
                   Step 3:  From ‘Array’ select ‘text list’ to array, and change its value to 1, 2 and 5.


                   Step 4:  Move ‘set text list’ to ‘on start’ block.








                   Step 5:  Create a variable ‘y’.

                   Step 6:  From variable, move the ‘set y to 0’ block to screen.


                   Step 7:  From ‘Math’ select two ‘Addition’ block and join them as shown:

                   Step 8:  Move the addition block to ‘set y’ block.














                   Step 9:  From ‘Array’ select three ‘list get value at 0’ block.

                   Step 10: Add ‘list get value at 0’ block to addition block.

                   Step 11: From the ‘list’ drop down, select ‘arr’.

                   Step 12: Move ‘set y’ block to ‘on start’ block.

                   Step 13: Change the value of ‘set y’ to 0, 1, 2.











                   66     Touchcode-VII
   63   64   65   66   67   68   69   70   71   72   73