Skip to main content
2 of 6
edited body
Dom Hastings
  • 24.7k
  • 4
  • 58
  • 94

JavaScript, 423

(function(i){if(s.match(/[^HQ9\+]/)){m='Source code contains invalid characters'}else{n=99,b=' bottle',j=' of beer',d=' on the wall',e='take one down, pass it around',k='go to the store, buy some more',f=', ';for(;n;)v+=[n,b,n-1?'s':m,j,d,f,n,b,n-1?'s':m,j,f,--n?e:k,f,n||'no more',b,d,'! '].join(m);h={H:'Hello World!',Q:arguments.callee+m,9:v};for(;c=i[n++];)m+=h[c]||''}alert(m)})((s=prompt()).split(m=v=''))

Didn't opt for the case-insensitive, would have cost too many characters. Not even close to some of the other entries, but was fun nonetheless!

I made a version with a less complete version of the song in 344:

(function(i){if(s.match(/[^HQ9\+]/)){m='Source code contains invalid characters'}else{n=99,b=' bottles of beer ',d='on the wall',e='take one down, pass it around',f=', ';for(;n;)v+=[n,b,d,f,n,b,f,e,f,--n||'no more',b,d,'! '].join(m);h={H:'Hello World!',Q:arguments.callee+m,9:v};for(;c=i[n++];)m+=h[c]||''}alert(m)})((s=prompt()).split(m=v=''))

but after seeing the other entries, I thought it was a bit of a cop out!

Dom Hastings
  • 24.7k
  • 4
  • 58
  • 94