Introduction To JavaScript - 060244
Introduction To JavaScript - 060244
JavaScript
Introduction
• JavaScript is a scripting language that
sits in the HTML code of a Web page.
• JavaScript is a browser-based scripting
language developed by Netscape in
1995 and implemented in all major
browsers.
• JavaScript is used to perform simple
functions within web pages.
© K.S. Mbise JavaScript Slide 2
Introduction cont…
• JavaScript is what is known as a client-
side scripting language.
• Client side means that it runs in the
browser on the client's computer, as
opposed to logic that is processed on
the server before the results are sent
back to the client's computer.
(1 of 1)
13 <!--
14 document.writeln(
15 "<h1>Welcome to JavaScript Programming!</h1>" );
16 // -->
17 </script>
18
19 </head><body></body>
20 </html>
welcome5.html
<html xmlns = "http://www.w3.org/1999/xhtml">
9 <head>
10 <title>Using Prompt and Alert Boxes</title>
(1 of 2)
11
12 <script type = "text/javascript">
13 <!--
14 var name; // string entered by the user
15
16 // read the name from the prompt box as a string
17 name = window.prompt( "Please enter your name", "GalAnt" );
18
19 document.writeln( "<h1>Hello, " + name +
20 ", welcome to JavaScript programming!</h1>" );
21 // -->
22 </script>
Fig. 7.7 Prompt dialog displayed by the window object’s prompt method.
Addition.html
9 <head>
10 <title>An Addition Program</title>
11
12
13
14
(1 of 2)
<script type = "text/javascript">
<!--
var firstNumber, // first string entered by user
15 secondNumber, // second string entered by user
16 number1, // first number to add
17 number2, // second number to add
18 sum; // sum of number1 and number2
19
20 // read in first number from user as a string
21 firstNumber =
22 window.prompt( "Enter first integer", "0" );
23
Addition.html
31
32 // add the numbers
33 sum = number1 + number2;
(2 of 2)
34
35 // display the results
36 document.writeln( "<h1>The sum is " + sum + "</h1>" );
37 // -->
38 </script>
39
40 </head>
41 <body>
42 <p>Click Refresh (or Reload) to run the script again</p>
43 </body>
44 </html>
number1 45
Fig. 7.9 Memory location showing the name and value of variable number1.
number2 72
Fig. 7.10 Memory locations after values for variables number1 and number2 have been input.
number2 72
sum 117
Fig. 7.11 Memory locations after calculating the sum of number1 and number2.