99 Bottles

Program the lyrics to 99 Bottles of Beer on the Wall.

by Matthew Pye

HTML

<div id="console-log"></div>

JavaScript

//Hack to mimic console within JSFiddle
var consoleLine = "<p class=\"console-line\"></p>";
console = {
    log: function (text) {
        $("#console-log").append($(consoleLine).html(text));
    }
};

//Begin exercise
function out(x) {
    console.log(x);
}

for (i = 99; i > 0; i--) {
    out(i);
    out(' bottles of beer on the wall'.);
    out(' bottle');
    out((i != 1) ? 's' : '');
    out(' of beer. You take one down, pass it around, ');
    out((i - 1 != 0) ? i - 1 : 'no more');
    out(' bottle');
    out((i - 1 != 1) ? 's' : '');
    out(' of beer on the wall. ');
};
out('No more bottles of beer on the wall, no more bottles of beer. Yada Yada, Yada Yada, no more bottles of beer on the wall.');