--- Functions ---
print("----連加----")
function test(s, e)
local a = 0
for i = s, e do
a = a+i
end
print(a)
end
test(1,10)
print("----Simple example----")
function Tax(price)
local tax = price * 0.21
print("Tax:" .. tax)
end
Tax(500)
print("----function that returns a value----")
function calculateTax(price)
return price * 0.21
end
local result = calculateTax(560)
print("Tax:" .. result)
print("----reusing the function but using variables----")
local bread = 130
local milk = 110
local breadTax = calculateTax(bread) --27.3
local milkTax = calculateTax(milk) --23.1
print("Bread Tax = " .. breadTax)
print("Milk Tax = " .. milkTax)
print("----multiple parameters----")
function displayInfo(name, age, country)
print(name .. " is " .. age .. " years old and is from " .. country .. ".")
end
displayInfo("Billy", 12, "Jupiter")
To embed this program on your website, copy the following code and paste it into your website's HTML: