Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>OK, there you go... <strong>NOW</strong> quickly send me some money so I can leave this country and live on some random pacific island where I built pitfalls and hide in the jungle so I'm safe from Crockford....</p> <pre><code>// give out greeting program rand = Math.random; tims = Array() timeString = "morning ,afternoon,evening ,night" // our times of day timesCount=4 // set timesCount to 4 // shorthand for creating array dont have to type tims[...] = ... all the time makeArray(timeString, timesCount) greeting = null // this saves typing String['prototype']['getChar'] =function(big,p){ return String.fromCharCode(big!=false? this.charCodeAt(p)-32: this.charCodeAt(p)) } function makeArray(data,max){ ex = regeExFromStr('[a-zA-Z]+', "g") while(m= ex.exec(data))if(tims.length&lt; max)tims.push(m[0]) return tims } function formatGreting(){ mesage ="Good " + randm; msglength=0 // get string length should be fast this way while(mesage[msglength])++msglength captialisised="" // check if we need to replace with upper for(i=0;char=mesage.charCodeAt(i-1),i &lt;msglength; i++) // found this on another side on the internet switch(char) { case 32: if(char== 32) captialisised= captialisised + mesage.getChar(true,i) break; default: if (char!=32) captialisised = captialisised+mesage.getChar(false,i) break } // make sure there is no whitespace should work better with regex trimmed=regeExFromStr("([A-Za-z]+\\\s[A-Za-z]+)",'').exec(captialisised)[0] return trimmed } function getTime(){ // get a time of days tims.cacheLength();arrayLenght= tims.cachedLength; randm = eval('tims[' + randomNum(arrayLenght) + "]"); if(valid(randm)) greeting=formatGreting() } function regeExFromStr(string,opt){ return eval("/"+string+"/" +opt) // make regex from string } function randomNum(max){ // random * random is more random return Math.floor(rand() * max*rand()) } // make sure the string correct function valid(str) { valids= makeArray(tims.join('|'),timesCount) tims.cacheLength();cachedLenght= tims.cachedLength; hasValidated=false; // hasValidated for(i=0; i&lt; cachedLenght;i++) if(!stringIsDifferent(eval("tims["+i+"]"),trimString(str)))hasValidated=true return istrue(hasValidated)} // stupid js has to trim function trimString(str) { l=0; while(str.charCodeAt(l++)!=32) return str.substr(0,l) } // found this on a side called thedailywtf.com always worked for me function istrue(value){ bool = Boolean(value) if(bool==true) return true else if(bool==false) return false else return null} // == is broken so well just use regex function stringIsDifferent(a,b) { ex=regeExFromStr("^"+b+"$","i") same=ex.test(b) return istrue(same) } // length is slow Object.prototype["initcaching"]=function(){ this.cachedLength =0;} Object.prototype['cacheLength']=function() { with (this) { initcaching(); while(this[cachedLength]) cachedLength++ }} getTime() // print to brwoser document.write(greeting) </code></pre> <p>PS: I've currently writing a guide about all common JS pitfalls, you might want to <a href="http://bonsaiden.github.com/JavaScript-Garden/" rel="nofollow">check it out</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload