Javascript - Rainbow Username String


SUBMITTED BY: Guest

DATE: Sept. 11, 2013, 8:02 p.m.

FORMAT: JavaScript

SIZE: 938 Bytes

HITS: 1157

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title></title>
  5. <script>
  6. function rainbowUser() {
  7. var username = "ROYGBPROYGBPROYGBPROYGBP";
  8. var rainbow = new Array('red', 'orange', 'yellow', 'green', 'blue', 'purple');
  9. var htmlString = "";
  10. var color;
  11. for (var i = 0; i < username.length; i++) {
  12. color = rainbow[(i % rainbow.length)];
  13. htmlString += '<span style="color:' + color + ';">' +
  14. username.substring(i, i+1) +
  15. '</span>';
  16. }
  17. document.getElementById('user').innerHTML = htmlString;
  18. }
  19. </script>
  20. </head>
  21. <body onload="rainbowUser();">
  22. <div id="user"></div>
  23. </body>
  24. </html>

comments powered by Disqus