Skip to content

Instantly share code, notes, and snippets.

@lindsayevans
Created August 19, 2010 00:27
Show Gist options
  • Save lindsayevans/536647 to your computer and use it in GitHub Desktop.
Save lindsayevans/536647 to your computer and use it in GitHub Desktop.
var PekingDuck = (function(_this){
// How many people this duck will feed
_this.feeds = 5;
_this.after_sydjs = false;
// Returns the number of ducks needed to feed the supplied number of people
_this.for = function(people){
if(isNaN(people)) return 'BBQ pork';
var f = people / _this.feeds, i = Math.floor(f), d = f - i > 0 ? i + ((f - i > 0.5) ? 1 : 0.5) : i;
return d + (_this.after_sydjs ? ' + Tsingtao.for('+people+')' : '') || 'Bacon!';
};
return _this;
})(PekingDuck || {});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PekingDuck.js</title>
</head>
<body>
<h1>PekingDuck.js</h1>
<script src="http://jscdn.net/jquery.js"></script>
<script src="peking_duck.js"></script>
<script>
$(function(){
var d, i = 0, t = $('<table><tbody></tbody></table>').appendTo('body').find('tbody');
while(i++ < 12){
d = PekingDuck.for(i);
$('<tr><th scope="row">'+i+' '+(i === 1 ? 'person' : 'people')+'</th><td>'+d+' duck'+(d === 1 ? '' : 's')+'</td></tr>').appendTo(t);
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment