🌱 Beginner's Guide lesson 2 of 12

Numbers and Text

Computers are, at heart, very fancy calculators. In this lesson you'll use steav2 to do maths, work with text, and meet the two simplest answers of all: yes and no.

Doing maths

jongyeytha can print the result of a calculation, not just text:

[ try-it.sts ]
bongSlanhOun "maths";
jongyeytha 2 + 3;
jongyeytha 10 - 4;
jongyeytha 6 * 7;
jongyeytha 7 / 2;
[ what it prints ]
5
6
42
3.5

The four basic operators (symbols that do something to values) are:

symbol meaning
+ add
- subtract
* multiply (there's no × key, so we use a star)
/ divide

Notice there are no quotes around the numbers. 2 + 3 is a calculation, and steav2 works out the answer before printing it.

Order of operations

Just like in school maths, multiplication and division happen before addition and subtraction. Use round brackets ( ) to choose the order yourself:

[ try-it.sts ]
bongSlanhOun "order";
jongyeytha 2 + 3 * 4;
jongyeytha (2 + 3) * 4;
jongyeytha -5 + 1;
[ what it prints ]
14
20
-4

A tiny surprise

Try this one:

[ try-it.sts ]
bongSlanhOun "surprise";
jongyeytha 0.1 + 0.2;
[ what it prints ]
0.30000000000000004

That's not a steav2 bug! Computers store decimal numbers in binary, and some decimals (like 0.1) can't be stored perfectly, so a tiny rounding error creeps in. Almost every programming language does the same. It's a fun fact to know, and it rarely matters.

Text

A piece of text is called a string (think of a string of letters, like beads on a necklace). In steav2, the type of text is called Ahsor, which means "letters". You write a string inside double quotes:

[ try-it.sts ]
bongSlanhOun "text";
jongyeytha "I am a string";
jongyeytha "123";
jongyeytha 123;
[ what it prints ]
I am a string
123
123

The last two print the same thing, but they're different: "123" is text that happens to contain digits, while 123 is a real number you can do maths with.

Joining text together

The + sign also joins strings, one after the other:

[ try-it.sts ]
bongSlanhOun "join";
jongyeytha "sour" + "dough";
jongyeytha "Hello, " + "world" + "!";
[ what it prints ]
sourdough
Hello, world!

Notice the space inside "Hello, ". steav2 never adds spaces for you, so if you want one, put it in the quotes.

Here's a very useful trick: if one side of a + is text, the other side is turned into text automatically. That means you can mix words and numbers:

[ try-it.sts ]
bongSlanhOun "mix";
jongyeytha "I have " + 3 + " cats";
jongyeytha "Two times four is " + 2 * 4;
[ what it prints ]
I have 3 cats
Two times four is 8

Careful with this one, though. steav2 reads + from left to right, and once it has text, every + after it is joining, not adding:

[ try-it.sts ]
bongSlanhOun "careful";
jongyeytha "total: " + 1 + 2;
jongyeytha "total: " + (1 + 2);
jongyeytha 1 + 2 + " is the total";
[ what it prints ]
total: 12
total: 3
3 is the total

In the first line, "total: " + 1 becomes the text "total: 1", and then + 2 sticks a 2 on the end. Brackets fix it, because the maths inside them happens first.

Yes and no

The last kind of value for today is the simplest: a value that is either true or false. These are called Booleans (after a mathematician called George Boole), and steav2 calls the type Boolean.

  • ok means true (yes)
  • ort means false (no)

You get Booleans when you ask steav2 a question, like "is 5 bigger than 3?":

[ try-it.sts ]
bongSlanhOun "questions";
jongyeytha 5 > 3;
jongyeytha 2 > 10;
jongyeytha 4 == 4;
jongyeytha "is 1 less than 2? " + (1 < 2);
[ what it prints ]
ok
ort
ok
is 1 less than 2? ok

Notice that "is equal to" is written with two equals signs, ==. We'll use these questions a lot when your programs start making decisions, a couple of lessons from now.

Your turn

  1. Work out how many minutes there are in a week (60 minutes, 24 hours, 7 days) and print it. Hint: multiply three numbers together.
  2. Print the sentence My age in 10 years: followed by your age plus ten, as a proper sum. Hint: remember the brackets trick from "Joining text together".
  3. Print whether 100 / 4 is equal to 25.

Solution for exercise 2:

[ try-it.sts ]
bongSlanhOun "age";
jongyeytha "My age in 10 years: " + (12 + 10);
[ what it prints ]
My age in 10 years: 22
  • steav2♡ help
  • Y2K✓ ready
  • wasminside
  • .stsvalid

best viewed at 1024x768 ☆ made with ♡ ☆ the reference is steav2's own docs