Jump to content

Module:Sandbox/sameboat2

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Sameboat (talk | contribs) at 06:32, 19 March 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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"
    local output = '';
    for index = 1,arg1 do
        output = output .. "\n|-" .. "\n|" .. arg1 .. "||" .. index .. ") n! = " .. factorial(index)
    end
    return "{|class=wikitable" .. "\n!colspan=3|Factorial function til " .. index .. "\n" .. output .. "\n|}";
end

return my_object