September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,25 +1 @@
|
|||
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();
|
||||
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`));
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
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