No edit summary |
m (fizzbuzz) |
||
Line 4: | Line 4: | ||
if whom == nil then return 'Hi!' end | if whom == nil then return 'Hi!' end | ||
return [[Hello, ]] .. whom .. '!' | return [[Hello, ]] .. whom .. '!' | ||
end | |||
function M:fizzbuzz() | |||
local r = '' | |||
for i = 1, 100 do | |||
local s = '' | |||
if i % 3 == 0 then | |||
s = s .. 'Fizz' | |||
end | |||
if i % 5 == 0 then | |||
s = s .. 'Buzz' | |||
end | |||
if s == '' then | |||
s = s .. i | |||
end | |||
r = r .. s .. "\n" | |||
end | |||
return r | |||
end | end | ||
return M | return M |
Revision as of 00:18, 4 June 2021
Documentation for this module may be created at Module:Sandbox/doc
local M = {}
function M:hello(whom)
if whom == nil then return 'Hi!' end
return [[Hello, ]] .. whom .. '!'
end
function M:fizzbuzz()
local r = ''
for i = 1, 100 do
local s = ''
if i % 3 == 0 then
s = s .. 'Fizz'
end
if i % 5 == 0 then
s = s .. 'Buzz'
end
if s == '' then
s = s .. i
end
r = r .. s .. "\n"
end
return r
end
return M