⭐ 1.5.1 Addition

View

The addition block takes two numbers (or variables containing numbers) and returns the sum.

 

Activity: Addition

To try out the addition block, as well as the other math operators, you will ask the help of a puppy.

The following activity adds two values stored in two variables called my Number and myNumber2 and the puppy tells the result.

Follow these steps:

  1. Click File New from the top menu to create a new project.
  2. Click the Choose a Sprite icon  in the Sprite menu to open the Sprite Library.
  3. Locate the sprite named Puppy and click on it to add it to your project.

 

  1. From the project, right-click the Cat and select delete to remove her from your project.
  2. Drag a  (when green flag clicked) block from the Events Block Palette to the Scripts Area.
  3. Drag a  (forever) block from the Control Block Palette and snap it to the  block.
  4. Create two new variables in the   “Variables” Block Palette and then click on.  The first should be called my Number and the second one myNumber2.


Figure 22: Creating two variables

 

Your Variables Block Palette should now look like Figure 22.

 

  1. Right-click on  in the Stage.
    1. Several options for how to display the variable appear:

 

  1. Select slider from the variable display menu.
    1. The variable display on the Stage turns into a slider.

 

10.   Right-click myNumber2 on the Stage and change it into a slider as well.

11.   Drag a  “think ()” block from the Looks Block Palette to the Scripts Area and snap it inside the “forever” block as shown below:

12.   Drag a  “() + ()” block from the Operators Block Palette and place it into the  “think ()” block.

 

13.   Drag the “my Number” variable from the Variables Block Palette into the first spot in the block. Drag the “myNumber2” variable from the “Variables” Block Palette into the second spot in the  block.

    1. Your script should now look like Figure 23.

 

Figure 23: Script for addition

 

14.   Change the title of your project in the space above the Stage to Addition Puppy and select File Save from the top toolbar.

 

Click the Green Flag and then click and drag the sliders on your variables on the Stage. The puppy instantly does the math and tells you the answer (Figure 24).

Figure 24: The puppy doing addition

Last modified: Thursday, 23 September 2021, 10:56 AM