Javascript  4(for)  Php  5 Logo
Home Examples Downloads FAQ Documentation Road Map Forums

"Hello World"

/* Let's print "Hello, World!" with colorful letters */ /* a function that returns a random color code in the form "#xxxxxx" */ function color() { var s=Math.floor(Math.random()*256*256*256).toString(16); return "#" + ("00000"+s).substr(-6); } /* a method that takes a plain text string, and apply HTML tags to render each character of the string with a random color */ String.prototype.colorize = function() { var o=''; for (var i=0;i<this.length;i++) { o += '<span style="color:'+color()+'">'+this.charAt(i)+'</span>'; } return o; }; /* a method that surround the string with an HTML tag that renders the string 6 times better. */ String.prototype.big = function() { return "<span style='font-size:6em'>"+this+"</span>"; }; print("Hello, World!".colorize().big()); /* Note: print() is not part of the javascript language, but is defined to make this package useful out of the box. */
Site design and content copyright (c) 2004,2005 Henri T.