Gets the result of basic math operations: addition, subtraction, multiplication, division, and exponents.
This block is like a simple calculator and follows all the typical rules of math operations. It gets the result of the operation and can be used wherever a number block is expected.
Examples
Example 1
Help the student study for her test! Give her different math questions, and she’ll tell you the answer.
Example 2
Each time the space bar is pressed, the monster will shrink to half its size.
Syntax
math_arithmetic
Parameters
Name | Type | Required? | Description |
---|---|---|---|
number (2) | The two numbers of the math operation |
Tips
- Positive numbers, negative numbers, and decimals are accepted.
- If a division operation that results in a decimal is used where an integer is expected, the result will be rounded up to the nearest integer. For example, a repeat loop given 4 ÷ 3 (= 1.3333) will repeat the code 2 times.
- To make longer operations, math blocks can be used inside of other math blocks in place of a single number.
Found a bug in the documentation? Let us know at support@code.org.