An integer number.
A Number is an integer such as 42
or -42
. More precisely, a Number is a signed 32-bit integer (two’s complement).
You can assign a number to a variable:
let num = 42;
basic.showNumber(42);
The following arithmetic operators work on numbers and return a Number:
1 + 3
1 - 3
3 * 2
7 / 3
The following relational operators work on numbers and return a Boolean:
(3 + 1) = 4
3 != 4
3 <= 4
3 < 4
4 >= 3
4 > 3
The show number function displays a number on the LED screen. For example, this code displays the number 42:
basic.showNumber(42);
Some functions return a number, which you can store in a variable.
For example the following code gets the display brightness
(using the brightness function) and stores the value in a variable named brightness
:
let brightness = led.brightness()
The math library includes math related functions.
For example, the absolute
function returns the returns the absolute value of input parameter x
:
let abs = Math.abs(-42);
basic.showNumber(abs);