Time for some JavaScript humour! 😜

I took all the semicolons from my CSS and used them as indentation in my JS

<body>
<style>
body { margin      : 0              }
body { background  : #111           }
div  { float       : left           }
div  { width       : calc(100%/256) }
div  { padding-top : calc(100%/256) }
</style>
<script>
;;var hue = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f']
;;for (r=0;r<hue.length;r++){
;;;;for (g=0;g<hue.length;g++){
;;;;;;for (b=0;b<hue.length;b++){
;;;;;;;;var pixel=document.createElement('div')
;;;;;;;;pixel.style.background='#'+hue[r]+hue[g]+hue[b]
;;;;;;;;document.body.appendChild(pixel)
;;;;;;}
;;;;}
;;}
</script>

Your scientists were so preoccupied with whether or not they could, they didn’t stop to think if they should.

Please reply with any useless, but amusing code you have 🤓

Comments (4)

Add a comment
Marco Alka's photo

Disclaimer: Very bad JS ahead. Do not copy that style!

well, the terminal code for SHPS is very old and hacky and contains crap, like

me.on('line', function f_commandline__on_line($line) {

    $line = $line.trim();
    var tokens = $line.split(' ');
    //ohmygod, this should really be exchanged with some eventing action
    switch (tokens[0]) {

        // a few commands here

        // The following sentence will destroy the AI's emotional memory. Very sad.
        case 'what do you see when you close your eyes':
        case 'exit': {

            libs.parallel.killAll();
            libs.main.killAllServers();
            process.exit(0); //todo: nice shutdown
            break;
        }

        case 'help': {

            me.write('We are truely sorry, but help has not been implemented, yet  :/\n');
            break;
        }

        case 'lick': {

            // I'm sorry, but I had to put this here...
            var buf = new Buffer('D........Q===', 'base64');// contains some song lyrics
            me.write(buf.toString('utf-8') + '\n');

            break;
        }

        case 'whoami': {

            me.write('root');
            break;
        }

        case 'cache': {

            me.write('Not Implemented yet');
        }
    }
}

The memory-destroying sentence will not even work, because I only switch for the first token.... I really should take some time to clean the module, but the web GUI is just more important at the moment :(

Nate Ebel's photo

next project: a linter that enforces this style

Max Bachhuber's photo

I don't get it

Tommy Hodgins's photo

CSS & Element Queries

In CSS, multiple properties in the same rule are separated by semicolons ';', and in JavaScript semicolons end a statement. In this example I had to write multiple 'redundant' CSS rules each containing only one property so I could avoid using a semicolon there, and in my JavaScript instead of indenting with tabs or spaces, I used empty statements at the start of the line to push my real code over. It's valid CSS and valid JS, but completely nonsensical formatting :D