Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language JavaScript

Date:04/20/05
Author:Brian Patrick Lee
URL:n/a
Comments:3
Info:n/a
Score: (2.70 in 23 votes)
/**
 * 99 Bottles of Beer on the Wall in JavaScript
 * This program prints out the lyrics of an old pub song.
 * Copyright (C) 1996, Brian Patrick Lee (blee@media-lab.mit.edu)
 */
if (confirm("Are you old enough to read about beer\n" +
	    "according to your local community standards?")) {
  for (i = 99 ; i > 0 ; i--) {
    j = i - 1;
    if (i != 1) { 
      icase = "bottles"; 
    } else { 
      icase = "bottle";
    }
    if (j != 1) {
      jcase = "bottles";
    } else {
      jcase = "bottle";
    }
    document.writeln(i + " " + icase + " of beer on the wall,");
    document.writeln(i + " " + icase + " of beer,");
    document.writeln("Take 1 down, pass it around,");
    if (j != 0) {
      document.writeln(j + " " + jcase + " of beer on the wall.");
    } else {
      document.writeln("No more bottles of beer on the wall!");
    }
    document.writeln()
  }
} else {
  document.write("You might want think about moving to another community.")
}

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Eponymous obfuscated versionJavaScribe01/09/094
Fully commented, OOP approach.Ariel Flesler03/28/080
using DOM and a closureChristof Donat03/07/060
With english numbers, DOM, and callbacksJoseph Taylor01/18/080

Comments

>>  Koni Joto said on 06/15/05 14:46:35

Koni Joto But what's about <br>s? The text looks ugly.

>>  Nox said on 01/18/06 17:29:31

Nox I was just reading a website about "Obfuscated Programming". So here is my 15 minute work =)

Simply Copy&Paste into a HTML. Testet with newest FF.

<script>var _=[' bottle',' of beer',' on the wall','Take one down, pass it around','If one of those bottles should happen to fall','Go to the store and buy some more.','No more '];document.writeln({$:function(_){var __='';if(_ instanceof Array)for(var $$ in _)__+=this.$(_[$$])+'<br>';return __||_;},$_:function(n){var $$=this.$(n?[n+_[0]+(n==1?'':'s')+_[1]+_[2],n+_[0]+(n-1?'s':'')+_[1]+'!',(n-1?_[3]:_[4]),n-1?(n+_[0]+(n==1?'':'s')+_[1]+_[2]+'!'):(_[6]+_[0]+'s'+_[1]+_[2]+'!'),'']:[_[6]+_[0]+'s'+_[1]+_[2],_[6]+_[0]+'s'+_[1]+'!',_[5],99+_[0]+'s'+_[1]+_[2]+'!']);if(n--){$$+=this.$_(n);}return $$;}}['$_'](99));</script>

>>  toxik said on 02/12/06 03:01:12

toxik Damnit, read the lyrics and produce them exactly as they should be.
(refering to the end espec.)

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: