Lesson_6

nostalgicisolatedΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

62 εμφανίσεις

1

Lesson 6

Introducing JavaScript

HTML and JavaScript
BASICS, 4
th

Edition

Barksdale / Turner

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

2

2

Objectives


Display Web page text with JavaScript.


Use HTML formatting tags both in and around
JavaScript code.


Create conditional statements with JavaScript.


Use the JavaScript alert() method.


Access the browser status line with
JavaScript.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

3

3

Vocabulary


binary code


compiler


condition


conditional
statement


interpretation


keywords


methods


objects


operators


parameter list

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

4

4

Vocabulary (continued)


programming
language


properties


<script> </script>
tags


scripting language


status line


syntax


token


variable

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

5

5

Hello World Wide Web


JavaScript is sometimes called a
programming language
, but it is more
accurate to call it a
scripting language
.


Both types of languages must be converted
from a human
-
readable form to a machine
-
readable form.


Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

6

6

Hello World Wide Web (continued)


For programming languages, the conversion
process is performed before the program runs
by a specialized piece of software called a
compiler
.


With a scripting language, however, it
happens automatically when the source code
is processed by the target program.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

7

7

Hello World Wide Web (continued)


The
<script></script> tags

mark the
beginning and end of a JavaScript section.


JavaScript is made up of invisible entities
called
objects

that contain a well
-
defined set
of capabilities.


JavaScript programmers call upon the
services of one or more specialized functions
known as
methods

within those objects.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

8

8

Enhancing Your Web Page


The
document.write()
method simply inserts
a string of characters into the standard HTML
text stream.


After the browser processes the HTML
document, the <script> </script> tags and
everything in between will be stripped out of
the page and replaced by the output of the
write() method.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

9

9

Creating Conditional Statements
in JavaScript


The
conditional statement

gives
programmers the ability to evaluate a specific
condition and then perform different actions
depending on the results of that evaluation.


A

keyword
is recognized as part of the
language definition.


A
variable

is a user
-
defined name for a
memory location whose value can change
over time.


Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

10

10

Creating Conditional Statements
in JavaScript (continued)


The JavaScript
if

statement also supports an
optional
else

clause, which defines the action
to take if the specified condition is not true.


A JavaScript condition will always consist of
two
tokens

separated by a
relational
operator
. A token can either be a variable
name (such as x or count) or a literal constant
(such as 10 or “hello”).

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

11

11

Creating Conditional Statements
in JavaScript (continued)


Relational Operators

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

12

12

Creating Conditional Statements
in JavaScript (continued)


JavaScript objects contain
properties

that
programmers can access to obtain information
about the object.


An important concept is that once the
condition has been evaluated, either the
if
statement block or the

else
statement block
will be executed

never both.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

13

13

Using the JavaScript alert()
Method


The
alert()

method allows a JavaScript
program to display a special dialog box that
notifies the user of an unexpected event or
that some sort of user action is required.


The

window
object is considered to be the
JavaScript default object, which means it is
not necessary to use its name explicitly.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

14

14

Accessing the Browser Status
Line


Your Web browser displays various messages
in a bar at the bottom of the browser window.
This area is called the
status line.


The message that the browser displays is
stored as a simple text string in a window
object property called
status.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

15

15

Accessing the Browser Status
Line (continued)


The graphic below shows both a status line and an
alert message.


Web page viewed with Internet Explorer 8

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

16

16

Summary

In this lesson, you learned:


The purpose of JavaScript.


How to display Web page text with
JavaScript.


How to use JavaScript objects.


How to use JavaScript methods.


How to use HTML formatting tags both in and
around JavaScript code.

Lesson 6

Barksdale / Turner

HTML and JavaScript BASICS 4E

17

17

Summary (continued)


How to create conditional statements with
JavaScript.


How to use the JavaScript alert() method.


How to access the browser status line with
JavaScript.