login

free javascript!!! cool_colors() function

i wrote this function 2 do stuff like the redblueredblue nasty nets on the side bar — u can add as many colors to the function as u like and it repeats the pattern, heres da code check it out!:


<script type='text/javascript'>
function cool_colors( the_string )
{

     var q=0;

     for(var i=0; i<the_string.length; i++)
     {

          document.write('<span style=\"color:'+arguments[q+1]+'\">'+the_string.charAt(i)+'</span>')

          if(the_string.charAt(i)!=' ')
          {

               q++;
               if(q>=(arguments.length-1))
                    q=0;

          }

     }
}

cool_colors('nasty nets','red','blue')

</script>

  9/5/07 2:58 pm




7 Comments »


guthrie i cant figure out how to call this function! am i missing something obvious??
i want to use this on my site!! :)))

mg

- mmmggg — 9/5/07 @ 4:34 pm


wooops i think i fixed it, try copying the code again :)

- guthrie — 9/5/07 @ 4:53 pm


what was the code you fixed so we can learn
thx

- charles — 9/5/07 @ 10:37 pm


if you insist!

it wasn’t a code problem it was some weird problem with quotation marks on the blog — for some reason putting them inside of <span> tags to color them (above) turned them into the fancy curly quotes, which is no good for code ;(((

so to fix it, instead of writing ” i wrote &#39;
(and actually to write the sentence above i had to write &amp;#39;)
(…and, to write that sentence i had to type &amp;amp;#39;, etc)
(too nerdy for nasty nts)

- guthrie — 9/5/07 @ 10:47 pm


thx

- charles — 9/5/07 @ 11:04 pm


enTITY encoding yo

- Jon Williams — 9/5/07 @ 11:36 pm


GAYD!

weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

- lowcast — 9/6/07 @ 12:53 am




RSS feed for comments on this post. TrackBack URI

Leave a comment

  • Login first if you are a user!
  • If a guest, please use form below (BTW, some basic html works, not img tags yet)