Expressions and Operations

Reporters report their value when clicked.

snap can do calculations for you. Operations such as _ + _ _ - _ _ * _ and _ / _ report the result of their calculations, so they are called "reporter" blocks. You can nest them inside each other:
(5 + 4) times 3  =   (5 + 4) · 3  =  9 · 3   =   27

  1. Talk with Your Partner Without using snap, determine what each of these expressions will report:
    1. (5 · 4) + 3
    2. (5 · 4) - 3
    3. (5 + 4) ÷ 3
    4. (5 - 4) · 3
    5. 5 ÷ (4 - 3)
    6. 5 ÷ ((4 + 3) - 2)
    7. (((5 + 4) · 3) - 2)
  2. You may want to review Designing Custom Blocks and Adding an Input.
  3. Experiment with round a number by giving it inputs like round 3.14 and round 401.9.
  4. Experiment with the mod block by giving it inputs like these. For what numbers does (number) mod (2) report 0 and when does it report 1?

    experiments with various numbers mod 2

  5. Now predict (without using snap) what (23) mod (2) will report.

The () mod () block reports the remainder when the first input is divided by the second. For example, 17 mod 5 reports 2 because when 17 is divided by 5, the remainder is 2.

When one number divides another evenly, the remainder is 0: 15 mod 5 reports 0. The Boolean expression n mod 2 = 0 reports true if n is divisible by 2 (meaning n is even) and false if n is odd (not divisible by 2 and so the remainder is not 0).