Transcript Unit5
Unit 2 — The Exciting World
of JavaScript
Lesson 5 — What Is
JavaScript?
Objectives
2
Understand the purpose of JavaScript.
Use the <SCRIPT> and </SCRIPT> tags.
Use JavaScript objects.
Use JavaScript methods.
Understand JavaScript syntax.
The Exciting World of JavaScript
Hello World Wide Web
JavaScript is a scripting language, interpreted by a
Web browser and inserted in an HTML page using
<SCRIPT> </SCRIPT> tags.
–
–
Must follow strict rules of “grammar” called syntax.
Must be precise, even down to upper or lower case.
<HTML>
<BODY>
<SCRIPT>
document.write("Hello World Wide Web!");
</SCRIPT>
</BODY>
</HTML>
3
The Exciting World of JavaScript
Hello World Wide Web (cont.)
JavaScript uses
–
–
–
4
Objects: Invisible entities that
have a defined set of capabilities.
Methods: Specialized functions
within an object that call the
services of the object. Invoked
after entering the name of the
object, followed by a period.
Parameter list: List of
information; provides a method
with what it needs to perform a
specific function.
The Exciting World of JavaScript
document.write("Hello");
Hello World Wide Web (cont.)
<HTML>
<HEAD>
<TITLE>HTML and
JavaScript</TITLE>
</HEAD>
<BODY>
<SCRIPT>
document.write("Hello World
Wide Web!");
</SCRIPT>
</BODY>
</HTML>
5
The Exciting World of JavaScript
Enhancing Your Web Page
Everything between the <SCRIPT> </SCRIPT> tags is
taken out and replaced by the string appearing in the
parameter of the write () method. HTML formatting tags
<CENTER> and <H3> will be processed normally.
<CENTER>
<H3>
<SCRIPT>
document.write("Welcome to JavaScript");
</SCRIPT>
</H3>
</CENTER>
6
The Exciting World of JavaScript
Conditional Statements
in JavaScript
A conditional statement tells
the browser (IF) a condition is
met, perform a function.
If not, (ELSE).
–
7
Perform a different function.
The Exciting World of JavaScript
if ( <condition> )
{
statement i1;
statement i2;
.
.
}
else
{
statement e1;
statement e2;
.
.
}
Conditional Statements
in JavaScript (cont.)
A condition is made up of two tokens and a
relational operator. The operators are
==
!=
<
>
<=
>=
8
is equal to
is not equal to
is less than
is greater than
is less than or equal to
is greater than or equal to
The Exciting World of JavaScript
Conditional Statements
in JavaScript (cont.)
For example:
<SCRIPT>
if (navigator.appName == "Netscape")
{
document.write("You are using Netscape Navigator");
}
else
{
document.write("You are not using Netscape Navigator.<BR>");
document.write("I'll bet you are using Microsoft Internet Explorer.");
}
</SCRIPT>
9
The Exciting World of JavaScript
Conditional Statements
in JavaScript (cont.)
In this case, Internet Explorer
is being used, so the else
alternative is invoked.
else
{
document.write("You are not using
Netscape Navigator.<BR>");
document.write("I'll bet you are
using Microsoft Internet Explorer.");
}
10
The Exciting World of JavaScript
Using the JavaScript Alert() Method
The alert () method
displays a dialog box to
alert the user that an event
occurred.
alert("Netscape Navigator
detected");
alert("Netscape Navigator
required");
11
The Exciting World of JavaScript
Accessing the Browser Status Line
The status line displays messages at the bottom of
a window and can be accessed with a JavaScript
program.
–
–
Must follow strict rules of “grammar” called syntax
Must be precise, even down to upper or lower case
<HTML>
<BODY>
<SCRIPT>
document.write("Hello World Wide Web!");
</SCRIPT>
</BODY>
</HTML>
12
The Exciting World of JavaScript
Accessing the Browser Status
Line (cont.)
The status line displays
messages at the bottom
of a window accessed
with a JavaScript
program.
window.status = "A string of text";
13
The Exciting World of JavaScript
Summary
14
You can explain the purpose of JavaScript.
You can use the <Script> and </Script> tags.
You can use JavaScript objects.
You can use JavaScript methods.
You can understand and apply JavaScript
syntax.
The Exciting World of JavaScript