Chapter 1: Variables, Inputs & Outputs
Programming is nothing more than controlling in a more direct way what P already use a computer in a number of ways, you want your computer to do. You proband you control it to some extent by the programs you use and the way that you use them. Still, without programming, you are always at the mercy of the programs designed by others. In this chapter, you will look at how you can begin to influence the computer’s behavior. Specifically, you will:
• Examine how you can put code inside a HyperText Markup Language (HTML) page
• Use dialog boxes to interact with the user • Learn how computers store data in variables
• Learn how to get data from the user
• Perform basic operations on data
Adding Code to HTML
Web pages provide a rich background for programming. With the knowledge of HTML that you already have, you can generate pages that look pretty good. For example, you can control how text looks and add images. You might even have some experience with the finer-grained control of cascading style sheets. Still, plain HTML pages lack true interactivity. The only way that the user can really exert any control over the page is by clicking on links. This is interesting, but that fun takes the user only so far.
Creating the Hello, World! Application
It would be interesting to make the page a little more dynamic. Both of the major browsers, Netscape Navigator and Microsoft Internet Explorer, support JavaScript, a scripting language that is perfect for adding interactive features to a Web page. Take a look at the following snippet of code: 3 Chapter 1 Variables, Input, and Output
<html>
<script>
//hello world
//the classic first program
alert(“hello world”);
</script>
</html>
If you save this code as a Web page, then load that page into a browser, it generates the screen shown in Figure 1.2. This code snippet consists of normal (if very abbreviated) HTML, but it uses some features you might not have seen before. The <script></script> tag set specifies to the browser that any code between the tags is not written in HTML, but in a scripting language. Both the Netscape Navigator and Microsoft Internet Explorer browsers use JavaScript, their default language, unless you specify another language. (Technically, Microsoft Internet Explorer runs a variant called Jscript, but the code works the same as either JavaScript or Jscript.)
So much for now folks, stick around for more JavaScript programming tutorials.
For more on Javascript programming and online entertainment, visit my site:
Http://funaddict.yolasite.com
For more on writing effective articles visit:
http://effective-articles.blogspot.com
Comments
Leave a comment Trackback