People

I teach a class in Javascript at my art school and each week we go through several examples. Whenever I personally try to learn something in the field of computer programming, I try to make sure I understand what each line of code is doing. I feel you will never be very good at something like Javascript if you just copy and paste code, you really need to understand what is going on in that code.

My students should already be pretty familiar with building basic websites with xhtml and css before they get into my class. I decided a good idea for the final project would be for each student to make a website about javascript, using examples that we went over in class, or, from other sources. Each page should have some javascript embedded in it. I will ask my students to comment their code. This will help in the explanation process. I suggest that users of these sites always view the source code for these pages. You can find that in the View menu of your browser.

I am asking for the students to explain the concepts of these javascript examples. I do believe that if you understand something well enough to explain it, then you must really know it. In a sense, the students will be building their own tutorials with these sites, tutorials that can be extended as time goes on.

I also believe that even understanding other people's code is not enough, you have to try to be creative and write some code of your own. In the beginning, a good way to do this is to take an example and try to lter it a little, change it even slightly to do something a bit different. You will find that these two principles, understanding and explaining javascript examples PLUS trying to create your own examples, will lead you to becoming a real web programmer.

Javascript Explanation: How to Welcome Your Vistor

I tried to comment the source code fairly extensively, so view that for more information.

When you first come to this page, there will be a javascript prompt that asks for your name. Once you type something and hit "OK", you will see a personalized welcome.

If you look at the source code,you will see a script element in the head. In that, you will notice that I declared a variable, yn, equal to the javascript prompt. This variable will store the contents of what the user types. In the html I created an h3 element with an id of "welcome". In the script element in the head I wrote a function, initWelcome(), which, when called, will create the text for that welcome h3. The function call occurs in the body tag by means of the onload attribute.