Jump to content

Module:Sandbox/sameboat2: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 11: Line 11:
my_object.hello = function( frame )
my_object.hello = function( frame )
local arg1 = frame.args[1] or "1"
local arg1 = frame.args[1] or "1"
if tonumber( frame.args[1] ) == 3 then
if frame.args[1] == 3 then
arg1 = 20
arg1 = 20
end
end
local output = '';
local output = '';
for index = 1,arg1 do
for index = 1,arg1 do

Revision as of 06:58, 19 March 2013

my_object = {};

function factorial(n)
    if n == 0 then
        return 1 --this returns the result 1 when passed zero
    else
        return n * factorial(n - 1)
    end
end
    
my_object.hello = function( frame )
    local arg1 = frame.args[1] or "1"
        if frame.args[1] == 3 then
            arg1 = 20
        end
    local output = '';
    for index = 1,arg1 do
        output = output .. "\n|-" .. "\n|" .. index .. "||" .. index .. ") n! = " .. factorial(index)
    end
    return "{|class=wikitable" .. "\n!colspan=3|Factorial function til " .. arg1 .. "\n" .. output .. "\n|}";
end

return my_object