Jump to content

Module:Example/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by QuickQuokka (talk | contribs) at 02:42, 29 August 2023 (Resolved). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {};

function p.count_fruit(frame)
    local num_bananas = tonumber(frame.args.bananas) or 0
    local num_apples = tonumber(frame.args.apples) or 0
    
    local conj_bananas = num_bananas == 1 and 'banana' or 'bananas'
    local conj_apples = num_apples == 1 and 'apple' or 'apples'
    
    return 'I have ' .. num_bananas ..  ' ' .. conj_bananas .. ' and ' .. num_apples .. ' ' .. conj_apples
end

return p