Introduction to programming via JavaScript
Handout 2

In this modification of the first exercise we are going to add to our script. 


<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="AUTHOR" content="Dana Lee Ling">
<link href="" rel="stylesheet" type="text/css">
<title>HTML 4.01 Charset ISO 8859-1 Skeleton</title>
<h1>Script Scrap</h1>

<script type="text/javascript">
var currBrowser=navigator.appName
if (currBrowser=="Microsoft Internet Explorer") { document.write("<br>Bill Gate&#39;s browser") }
if (currBrowser=="Netscape") { document.write("<br>This browser owned by AOL Time/Warner") }
if (currBrowser=="WebTV Internet Terminal") { document.write("<br>Buy a real computer") }


The third line introduces a variable, currBrowser. currBrowser is loaded with the application name for the browser the user is using. The fourth line then writes the contents of the variable to the web page itself. These lines demonstrate loading a variable and writing a variable.  In other programming languages the variables have to be defined in a declaration at the start of the program, and each variable is of a specific type: text, integer, decimal number.  In JavaScript variables are flexible boxes into which any kind of value can be tossed.

The fifth through seventh lines then write a comment based on the type of browser a person is using. The if-then construction used in these lines will be covered in class on the board.

IS 201 Course Page Lee Ling Courses Page College of Micronesia-FSM Home Page