|
Departments Info Home Page Articles Software GoodiesExplanations How do they do that? The Web in FocusResources Web Site Stuff Tech Books E-Books Tech Toys Web Hosting LinksWomen Opinion Tech Women Women's StudiesTech News Computer Security Databases Java Linux MP3 PC Software Robotics Site Owner Tech Latest Web Development XMLSpread the Word Newsletter
Recommend this Page
Site Info Legal Disclaimer
Privacy
Contact
Lighter Side Crazy for Life crazy for romance Crazy for Kitties Crazy for Dogs Crazy for CowsCopyright 2000-2001, hertechnology.com |
Your Second Program This time the focus is on programming again. If you've never written any sort of program, take a minute to read Your First Program. In the first programming article, I mentioned a few points about programming in general: patience and attention to detail. These points are still super important -- you just can't program without them! From the first program The first program introduced an important aspect of a program -- statements. A statement is similar to a sentence in English; it is a complete unit in the programming language that accomplishes something. If tests The second program will also be in JavaScript inside an HTML file and will make use of statements similar to those used in the first program. The second program will also make use of a conditional -- an "if" statement. You use if statements in regular conversation frequently: "If it's sunny tomorrow, I'm going to work in the garden, otherwise, I'll catch up on paperwork inside". That statement has several parts.
A programming sort of thing to say might be: "If the browser is Netscape, print out 'Hey Netscape user!', otherwise, print out 'Hey IE user!'". In JavaScript, you can say something similar, but you have to use the particular words and syntax that JavaScript wants to see.
If you look closely, you'll see I added some ()'s and a ; to the text. The ; is optional, but the ()'s are necessary. They tell Javascript what the if test is. Inside of the ()'s, you will see a double equals sign ==. That means to compare two things and see if they are the same or not. The term else identifies the stuff to do when the if test is false. It means "otherwise" in English. The first program used the document.writeln command to print a message to the screen. It does the same thing here. The first program also used navigator.appName -- this little gizmo gives you the name of the browser you are running when you load the HTML page with the JavaScript. The if test takes name of the browser and compares it to the word Netscape. If the name is exactly Netscape, the if test is true, otherwise the if test is false. |
|