Learn Lua · First steps · Lesson 4 of 4
True or false
A comparison gives true or false. These two values are called booleans:
3 > 2 --> true
10 <= 9 --> false
"Ada" == "Ada" --> true
5 ~= 5 --> false== asks whether two values are equal, and ~= asks whether they're different. (A single
= gives a name a value.)
and, or and not combine booleans. a and b is true only when both are true.
a or b is true when at least one is. not a turns true into false, and false into true:
local total = 64
local express = false
total >= 50 and not express --> true
total > 100 or express --> falsenil means "no value". or is also a way to give a fallback: when the value on its left
is nil or false, you get the value on its right instead. tonumber reads a number from
text, and gives nil when the text isn't a number:
tonumber("12") or 0 --> 12
tonumber("lots") or 0 --> 0Steps
- Set
bigto whethertotalis 50 or more. - Set
freeDeliveryto whether the order is big and isn't express. - Set
discountto whether the customer is a member or the total is over 100. - Set
counttoquantityas a number, or 0 when it isn't one.
Show a hint
Each answer is a single comparison or a few joined with and, or and not. You can use
big in the lines after it, as in big and not express.