Pathways to CyberInfrastructure

   

TFS


Shodor > CyberPathways > Workshops 2007 > TFS



Wednesday, Feb 14

Today's class was a big step forward in javascript programming. The students created web pages that displayed image galleries. Their pages allowed users to click through a looping set of images. In order to do this, students had to learn a number of programming concepts.

First, they created a basic HTML page with an image tag and a javascript section. This was mostly review from previous classes. Some students had attended Monday's class on rollovers, which had introduced these same elements. Next, we learned about the "onclick" attribute. Students experimented with changing the image's source to a second image on a click.

Diving into the real meat of the lesson, we talked about what a variable was and how you could use it. For the gallery, students figured out that they needed to have a "counter" variable to represent which image the user was looking at. This counter would change when the user clicked. But after implementing the counter, they realized that they also needed an "if" statement: if the counter got to be bigger than the number of pictures, it would be reset to zero.

Once they implemented this final part of the program, their image galleries worked beautifully!


Not Logged In. Login
©1994-2024 Shodor