Sunday, March 13, 2005

Random Links JavaScript

With spring break being under way, and having the ability to put off the homework for an evening, I decided that I would take another look at writing a little JavaScript that would randomly display links and descriptions to three blogs that I read. About a month ago I started looking into this and was unable to find anything that had been written and posted to the web that did what I was looking for. Most of what I found would select one entry out of a list and display it. That script is really simple, but didn’t do what I needed. Building on what I found, I was able to write a script that would suit my needs. I am sure that the algorithm isn’t the most optimized piece of code, however, it does work, and serves as my first ever piece of home-grown JavaScript.

JavaScript is pretty easy to use, but it has its quirks. I am not a big fan of un-typed languages as it makes it harder to understand what is going on. Also, it seemed that browser side debugging is rather mystical. In IE, I never would have been able to figure out what I had done wrong. Thank goodness for FireFox, and its JavaScript console, it made debugging almost bearable.

I am reasonably pleased that I was able to figure out the simple script. Plugging it into Blogger was more difficult than writing the actual script. Now that I have an inkling of how JavaScript works, I am getting ideas for other interesting scripts that could be written to add functionality to this blog. When I find more time and desire, more scripts will be forthcoming.

As I wasn’t able to find a script that did exactly what I wanted, I thought that I would share what I wrote. Here is a link to a page with an example and source for the JavaScript that will display three random pieces of content out of a larger array. It is really quite elementary, but was a good first step for me with regard to JavaScript. Any feedback is welcomed.

No comments: