Difference between revisions of "User:Frantik/99bottles"
From The 3geez Wiki
(→Output) |
|||
| (6 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | For http://99-bottles-of-beer.net/ | ||
| + | === Winter Code === | ||
| + | <nowinter> | ||
| + | <pre> | ||
| + | {{#function | formatNum | ||
| + | || {{#if | {{#1}} || {{#1}} || no more }} bottle{{#if | {{#1 == 1}} || || s}} | ||
| + | }} | ||
| + | |||
| + | {{#for | {{#i @= 99}} || {{#i >= 0}} || {{#i --}} || | ||
| + | {{#bottles | @= | {{#formatNum | {{#i}} }} }} | ||
| + | {{#ucfirst | {{#bottles}} }} of beer on the wall, {{#bottles}} of beer.<br /> | ||
| + | {{#if | {{#i}} | ||
| + | || Take one down and pass it around, {{#formatNum| {{#i - 1}} }} | ||
| + | || Go to the store and buy some more, 99 bottles | ||
| + | }} of beer on the wall. | ||
| + | |||
| + | }} | ||
| + | </pre> | ||
| + | </nowinter> | ||
| + | === Equivalent PHP Code === | ||
<pre>function formatNum($num) | <pre>function formatNum($num) | ||
{ | { | ||
| Line 11: | Line 31: | ||
"Take one down and pass it around, " . formatNum($i - 1) : | "Take one down and pass it around, " . formatNum($i - 1) : | ||
"Go to the store and buy some more, 99 bottles" | "Go to the store and buy some more, 99 bottles" | ||
| − | ) . " of beer on the wall.\n\n";} | + | ) . " of beer on the wall.\n\n"; |
| + | } | ||
</pre> | </pre> | ||
| − | {{#function|formatNum|| | + | === Output === |
| − | {{#if|{{#1}}|{{#1}}|no more}} bottle{{#if|{{#1 == 1}}| | | + | {{#function | formatNum |
| − | + | || {{#if | {{#1}} || {{#1}} || no more }} bottle{{#if | {{#1 == 1}} || || s}} | |
| − | + | }} | |
| − | |||
| − | {{#bottles}} of beer on the wall, {{#bottles}} of beer.<br /> | + | {{#for | {{#i @= 99}} || {{#i >= 0}} || {{#i --}} |
| − | {{#if | {{#i}} | Take one down and pass it around, {{#formatNum|{{#i - 1}}}} | Go to the store and buy some more, 99 bottles }} of beer on the wall | + | || |
| + | |||
| + | {{#bottles | @= | {{#formatNum | {{#i}} }} }} | ||
| + | {{#ucfirst | {{#bottles}} }} of beer on the wall, {{#bottles}} of beer.<br /> | ||
| + | {{#if | {{#i}} | ||
| + | || Take one down and pass it around, {{#formatNum| {{#i - 1}} }} | ||
| + | || Go to the store and buy some more, 99 bottles | ||
| + | }} of beer on the wall. | ||
}} | }} | ||
Latest revision as of 23:56, 13 August 2007
For http://99-bottles-of-beer.net/
Winter Code
<nowinter>
{{#function | formatNum
|| {{#if | {{#1}} || {{#1}} || no more }} bottle{{#if | {{#1 == 1}} || || s}}
}}
{{#for | {{#i @= 99}} || {{#i >= 0}} || {{#i --}} ||
{{#bottles | @= | {{#formatNum | {{#i}} }} }}
{{#ucfirst | {{#bottles}} }} of beer on the wall, {{#bottles}} of beer.<br />
{{#if | {{#i}}
|| Take one down and pass it around, {{#formatNum| {{#i - 1}} }}
|| Go to the store and buy some more, 99 bottles
}} of beer on the wall.
}}
</nowinter>
Equivalent PHP Code
function formatNum($num)
{
return (($num) ? $num : 'no more') . ' bottle' . (($num == 1) ? '' : 's');
}
for ($i = 99; $i >= 0; $i--)
{
$bottles = formatNum($i);
echo ucfirst($bottles) . " of beer on the wall, $bottles of beer.\n" .
($i ?
"Take one down and pass it around, " . formatNum($i - 1) :
"Go to the store and buy some more, 99 bottles"
) . " of beer on the wall.\n\n";
}
Output
{{#function | formatNum || {{#if | {{#1}} || {{#1}} || no more }} bottle{{#if | {{#1 == 1}} || || s}} }}
{{#for | {{#i @= 99}} || {{#i >= 0}} || {{#i --}} ||
{{#bottles | @= | {{#formatNum | {{#i}} }} }}
{{#ucfirst | {{#bottles}} }} of beer on the wall, {{#bottles}} of beer.
{{#if | {{#i}}
|| Take one down and pass it around, {{#formatNum| {{#i - 1}} }}
|| Go to the store and buy some more, 99 bottles
}} of beer on the wall.
}}