Monday, November 30, 2009

9. Javawocky and other strange languages

To gain information about people visiting your website, you can use client side programming like Javascript. It is limited in the amount of information it can handle, unlike server side programming, which can deal with complex queries (eg TfL Journey Planner). Javascript (not to be confused with Java) can also add interest to a website.

As a complete novice to programming, Javascript can be daunting but our lecturer Richard Butterworth recommended we remember the seven pillars of programming wisdom:

1. variables
2. input and output
3. arrays
4. sequence
5. selection or conditions
6. iteration 
7. procedures or functions

I produced this webpage using Javascript. A prompt asks if you are interested in news or sport. If you choose news, you are then asked where you live. Based on your response, a link to the BBC News website for your region will appear. If you select sport, you then choose from cycling, golf, football and tennis and a link will appear that will take you to the relevant page on the BBC Sports website. Unfortunately I couldn't figure out how to deal with invalid responses.

If you view the source for the webpage, you will see that I have defined the variables first before adding the conditions and functions. Originally, I didn't use parsing and it worked to an extent, however, it's advisable to add this function to ensure that your commands work properly.

You might need to check that the web brower isn't blocking your script. My webpage works in Firefox but the prompt was blocked when I tested it in Internet Explorer 8.





This was produced using the alert function. If you click on the box, you will see a message.

No comments:

Post a Comment