Learn Lua · First steps · Lesson 4 of 4

True or false

A comparison gives true or false. These two values are called booleans:

LUA
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:

LUA
local total = 64
local express = false
total >= 50 and not express  --> true
total > 100 or express       --> false

nil 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:

LUA
tonumber("12") or 0    --> 12
tonumber("lots") or 0  --> 0

Steps

  1. Set big to whether total is 50 or more.
  2. Set freeDelivery to whether the order is big and isn't express.
  3. Set discount to whether the customer is a member or the total is over 100.
  4. Set count to quantity as 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.