Created
August 19, 2010 00:27
-
-
Save lindsayevans/536647 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 || {}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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