Learn Lua · First steps · Lesson 2 of 4
Naming values
local gives a value a name. After that, the name stands for the value, so you can use
it in sums:
local price = 4.50
local tickets = 3
price * tickets --> 13.5A name can be given a new value later. The new value can use the old one, which is how you add to a running total:
local count = 10
count = count + 5
count --> 15Names can't contain spaces, and capital letters matter: ticketPrice and TicketPrice
are different names. Pick names that say what the value is. If the price changes, you
change it in one place and every sum that uses price follows.
Steps
- Set
subtotalto the price of all the tickets, usingpriceandtickets. - Return
total: the subtotal plus the booking fee. - Return
perTicket: the total divided by the number of tickets.
Show a hint
Use the names rather than the numbers they hold, so price * tickets instead of
4.50 * 4. A name can be used in the lines after the one where it's made.