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:

LUA
local price = 4.50
local tickets = 3
price * tickets  --> 13.5

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

LUA
local count = 10
count = count + 5
count  --> 15

Names 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

  1. Set subtotal to the price of all the tickets, using price and tickets.
  2. Return total: the subtotal plus the booking fee.
  3. 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.