Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/DM224b
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
--Gammaburst_3000 Google Code-in 2017, Introduction to Lua in Wikipedia. --[Lua task #03] Create your own Lua module on English Wikipedia: Google code-in local p = {} -- p stands for package function p.hello( frame ) return "Hello, world!" end --[Lua task #4] GCI p.Hi = function(frame) strName = frame.args.name or "Jimbo" return "Hello from Lua to my friend " .. strName .. ".<br>" end --[Lua task #5 and #6] GCI function p.temperature( frame ) cel = frame.args.celsius or 0 fah=(cel*9/5)+32 msg = cel .. " degree celsius is "..fah.." degrees fahrenheit.<br>" if tonumber(cel)>9 then msg = msg .. " It is warm." else msg = msg .. " It is cold." end return msg end --[Lua task #7] GCI p.times = function(frame) local num = tonumber( frame.args.num ) or 2 local out = "<b>" .. num .. " times table<br>" .. "</b>" for i = 1, 10 do out = out .. i * num .. "<br>" end return out end --edit1 p.times1 = function(frame) local num = tonumber( frame.args.num ) or 2 local out = "<b>" .. num .. " times table<br>" .. "</b>" for i = 1, 10 do out = out .. num .. " times " .. i .. " is " .. i * num .. "<br>" end return out end --edit2 p.times2 = function(frame) local num = tonumber( frame.args.num ) or 2 local out = "<b>" .. num .. " times table<br>" .. "</b>" for i = 1, 12 do out = out .. num .. " times " .. i .. " is " .. i * num .. "<br>" end return out end -- --[Lua Task #8] GCI -- p.mum = function(frame) local family = {"Dad", "Mum", "Uncle Stan", "Aunty Elsie", "Brian"} local msg = "" msg = msg .. "Hello " .. family[2] .. "<br>" return msg end --edit1: change to first member p.mum1 = function(frame) local family = {"Dad", "Mum", "Uncle Stan", "Aunty Elsie", "Brian"} local msg = "" msg = msg .. "Hello " .. family[1] .. "<br>" return msg end --edit2: loop 5 times p.mum2 = function(frame) local family = {"Dad", "Mum", "Uncle Stan", "Aunty Elsie", "Brian"} local msg = "" for i=1, 5 do msg = msg .. "Hello " .. family[i] .. "<br>" end return msg end --edit3: add two members p.mum3 = function(frame) local family = {"Dad", "Mum", "Uncle Stan", "Aunty Elsie", "Brian"} family[6]="James" family[7]="Tabby" local msg = "" for i=1, 5 do msg = msg .. "Hello " .. family[i] .. "<br>" end return msg end --edit4: change loop count to size of table p.mum4 = function(frame) local family = {"Dad", "Mum", "Uncle Stan", "Aunty Elsie", "Brian", "James", "Tabby"} local msg = "" for i=1, #family do msg = msg .. "Hello " .. family[i] .. "<br>" end return msg end --edit5: add another member to the table p.mum5 = function(frame) local family = {"Dad", "Mum", "Uncle Stan", "Aunty Elsie", "Brian", "James", "Tabby"} family[8]="Brienne" local msg = "" for i=1, #family do msg = msg .. "Hello " .. family[i] .. "<br>" end return msg end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/DM224b/doc
(
edit
)