|
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 |
First Program Have you ever wanted to write a computer program? Or are you curious about what programming is like? If you follow along with this column, you can join the ranks of the programming elite! Or, you may ask yourself how anyone can do this of their own free choice! Hopefully, either way you'll get taste of what programming is like. Preparations Before we start, you have to have the following:
JavaScript and HTML JavaScript is a series of instructions that your browser understands and executes. The kinds of instructions that you can enter are restricted -- you have to follow the language and syntax of JavaScript (as decided upon by the designers of the language). JavaScript code can be kept in a separate file, but it can also be in the file with the HTML tags. (HTML? HTML is the basic stuff that browsers process to put your web page on the screen. It consists of the text you want to display, plus tags that control how the text looks, what's a link, where the images are located, and more. We'll use some simple HTML to create a page for the JavaScript. If you don't know HTML, don't worry. You can copy and paste the code from the screen. All you need to know how to do is edit a file with a TEXT editor like Notepad.) Here is the HTML document that we will start with. Note: you can type HTML tags in upper or lowercase. They are the same.
<html> The code By tradition, the first computer program someone writes in a new language prints "Hello World!" on the screen. (Some people like to have the first programs print something else, but, hey, I'm something of a traditionalist.) JavaScript can be in the head of your document or in the body. Don't worry now why you might want to put something in one place or the other. We're going to put this first program in the body. Also, to make the program a little more interesting, we'll have it show which browser you are running when you load the HTML page with the script. Inside of HTML, JavaScript needs to be surrounded by <SCRIPT> tags, so we will tell the browser a script is coming with the opening <SCRIPT> tag and end it with the closing </SCRIPT>. Because some old browsers don't like scripts, we will put the script code inside of an HTML comment. Below you will see the script tags and the comment tags added to the basic HTML.
<html> Now we want to print "Hello World!" (without the quotes) to the screen. JavaScript uses a command called document.writeln to do the printing to the screen. We put what we want to write inside of double quotes, inside of parenthesis, like so: document.writeln("Hello World!"); (remember, no creative liberties -- you must use the exact syntax with parenthesis and an opening and closing quote). Add that statement after the opening SCRIPT tag:
<html> |
|