March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -1,10 +1,13 @@
// Line breaks are in HTML
var beer = 99;
while (beer > 0)
{
document.write( beer + " bottles of beer on the wall<br>" );
document.write( beer + " bottles of beer<br>" );
document.write( "Take one down, pass it around<br>" );
document.write( (beer - 1) + " bottles of beer on the wall<br>" );
beer--;
while (beer > 0) {
var verse = [
beer + " bottles of beer on the wall,",
beer + " bottles of beer!",
"Take one down, pass it around",
(beer - 1) + " bottles of beer on the wall!"
].join("\n");
console.log(verse);
beer--;
}

View file

@ -1,2 +1,10 @@
// Line breaks are in HTML
var beer; while ((beer = typeof beer === "undefined" ? 99 : beer) > 0) document.write( beer + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" + beer + " bottle" + (beer != 1 ? "s" : "") + " of beer<br>Take one down, pass it around<br>" + (--beer) + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" );
let beer = 99;
while (beer > 0) {
let verse = `${beer} bottles of beer on the wall,
${beer} bottles of beer!
Take one down, pass it around
${beer-1} bottles of beer on the wall`;
console.log(verse);
beer--;
}

View file

@ -1,21 +1,2 @@
// Line breaks are in HTML
function Bottles(count){
this.count = (!!count)?count:99;
this.knock = function(){
var c = document.createElement('div');
c.id="bottle-"+this.count;
c.innerHTML = "<p>"+this.count+" bottles of beer on the wall</p>"
+"<p>"+this.count+" bottles of beer!</p>"
+"<p>Take one down,<br>Pass it around</p>"
+"<p>"+(--this.count)+" bottles of beer on the wall</p><p><br></p>";
document.body.appendChild(c);
}
this.sing = function(){
while (this.count>0) { this.knock(); }
}
}
(function(){
var bar = new Bottles(99);
bar.sing();
})();
var beer; while ((beer = typeof beer === "undefined" ? 99 : beer) > 0) document.write( beer + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" + beer + " bottle" + (beer != 1 ? "s" : "") + " of beer<br>Take one down, pass it around<br>" + (--beer) + " bottle" + (beer != 1 ? "s" : "") + " of beer on the wall<br>" );

View file

@ -1,18 +1,25 @@
function bottleSong(n) {
if (!isFinite(Number(n)) || n == 0) n = 100;
var a = '%% bottles of beer',
b = ' on the wall',
c = 'Take one down, pass it around',
r = '<br>'
p = document.createElement('p'),
s = [],
re = /%%/g;
while(n) {
s.push((a+b+r+a+r+c+r).replace(re, n) + (a+b).replace(re, --n));
}
p.innerHTML = s.join(r+r);
document.body.appendChild(p);
function Bottles(count) {
this.count = count || 99;
}
window.onload = bottleSong;
Bottles.prototype.take = function() {
var verse = [
this.count + " bottles of beer on the wall,",
this.count + " bottles of beer!",
"Take one down, pass it around",
(this.count - 1) + " bottles of beer on the wall!"
].join("\n");
console.log(verse);
this.count--;
};
Bottles.prototype.sing = function() {
while (this.count) {
this.take();
}
};
var bar = new Bottles(99);
bar.sing();

View file

@ -1,12 +1,18 @@
(function(){var beer = 99,string='';
while (beer > 0)
{
string+=beer+"bottles of beer on the wall\n"+ //inline line appending shouldn't be as expensive.
beer +
"bottles of beer\nTake one down, pass it around\n"+
(--beer)+
" bottles of beer on the wall\n" ;
function bottleSong(n) {
if (!isFinite(Number(n)) || n == 0) n = 100;
var a = '%% bottles of beer',
b = ' on the wall',
c = 'Take one down, pass it around',
r = '<br>'
p = document.createElement('p'),
s = [],
re = /%%/g;
while(n) {
s.push((a+b+r+a+r+c+r).replace(re, n) + (a+b).replace(re, --n));
}
p.innerHTML = s.join(r+r);
document.body.appendChild(p);
}
console.log(string);
})()
window.onload = bottleSong;