Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-1.js
Normal file
13
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-1.js
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
var beer = 99;
|
||||
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--;
|
||||
}
|
||||
10
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-2.js
Normal file
10
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-2.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
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--;
|
||||
}
|
||||
11
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-3.js
Normal file
11
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-3.js
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var bottles = 99;
|
||||
var songTemplate = "{X} bottles of beer on the wall \n" +
|
||||
"{X} bottles of beer \n"+
|
||||
"Take one down, pass it around \n"+
|
||||
"{X-1} bottles of beer on the wall \n";
|
||||
|
||||
function song(x, txt) {
|
||||
return txt.replace(/\{X\}/gi, x).replace(/\{X-1\}/gi, x-1) + (x > 1 ? song(x-1, txt) : "");
|
||||
}
|
||||
|
||||
console.log(song(bottles, songTemplate));
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
// 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>" );
|
||||
|
|
@ -0,0 +1 @@
|
|||
Array.from(Array(100).keys()).splice(1).reverse().forEach(n => console.log(`${n} bottle${n !== 1 ? 's' : ''} of beer on the wall\n${n} bottle${n !== 1 ? 's' : ''} of beer\nTake one down, pass it around\n${n - 1} bottle${n - 1 !== 1 ? 's' : ''} of beer on the wall\n\n`));
|
||||
25
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-6.js
Normal file
25
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-6.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
function Bottles(count) {
|
||||
this.count = count || 99;
|
||||
}
|
||||
|
||||
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();
|
||||
18
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-7.js
Normal file
18
Task/99-bottles-of-beer/JavaScript/99-bottles-of-beer-7.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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);
|
||||
}
|
||||
|
||||
window.onload = bottleSong;
|
||||
Loading…
Add table
Add a link
Reference in a new issue