JavaScript - PowerPoint PPT Presentation

About This Presentation
Title:

JavaScript

Description:

Chapter 19 JavaScript – PowerPoint PPT presentation

Number of Views:124
Avg rating:3.0/5.0
Slides: 13
Provided by: emic157
Category:

less

Transcript and Presenter's Notes

Title: JavaScript


1
Chapter 19
  • JavaScript

2
JavaScript
  • Interpretive programming language
  • Its designed to work inside web pages uses
    ltscriptgt tag
  • Ex. ltscript languagejavascriptgt lt/scriptgt
  • It can be embedded in anywhere in the XHTML code
  • Nesting ltscriptgt tag generates a syntax error
  • Case sensitive sum, Sum, SUM are different

3
JavaScript
  • You need to know three major things to learn a
    programming language now
  • Language Syntax/Rules
  • Event handling
  • Object Oriented Programming (OOP) concept

4
JavaScript
  • Language Syntax/Rules
  • Variable symbolic name can store a value
  • Identifiers begin with letter, underscore, or
    dollar sign
  • Types number 30, 3.14, -25, -2.4
  • Boolean true or false (reserved words)
  • String 25 dollars, totalvalue
  • Var sum 100
  • Name tim
  • Scope global V.S. local (Var statement)
  • Constants const pi 3.14
  • Special character \

5
JavaScript
  • Statements a line of JavaScript code
  • Use sign -gt x 20 y x
  • Must end with a -gt x y 20
  • Must not be broken in to two lines.
  • Comments // inline comments
  • / block comments /

6
JavaScript
  • Expressions Operators
  • Assignment operators , , -, , /
  • y 30 x x y x y
  • Comparison operators , !, , !, gt, gt, lt,
    lt
  • A (x y) B (z gt 20)
  • Arithmetic operators , -, , /, , , - -, and
    (negative)
  • x10 x x y5 y- - y
  • Logical Operators (and), II (or), ! (not)
  • (T F) (F T) (F F) (F F) (! T) False
  • (T F) (F T) (T T) (T T) (! F) True
  • x true yfalse z !( x y) z ?

7
JavaScript
  • Control Structures - Conditional (if and switch)
  • if (condition) true block
  • else false block
  • switch (expression)
  • case label1 statement break
  • case label2 statement break
  • default statement
  • see example 19.5

8
JavaScript
  • Control Structures loops
  • Loops need a control value/counter to set the
    looping time
  • for loop
  • for (initial value of counter condition
    increment)
  • looping statements
  • for (counter0 counterlt10 counter)
  • document.write (for loop
    counter ltbr/gt)
  • How many time does this loop go?

9
JavaScript
  • Control Structures loops
  • while loop
  • while (condition) looping statements
  • counter 0
  • while (counter lt 10)
  • document.write (while loop counter
    ltbr/gt)
  • counter
  • // How many time does this loop go?
  • See example 19.6, 19.7

10
JavaScript
  • Control Structures loops
  • do while loop
  • do looping statements while (condition)
  • counter 0
  • do
  • document.write (do while counter
    ltbr/gt)
  • counter
  • while (counter lt 10)
  • How many time does this loop go?

11
JavaScript
  • Control Structures loops
  • infinite loops loop does not have a control
    value/counter to set the looping time

12
JavaScript
  • Window input and output method
  • You should not put XHTML tags in output string
  • Id prompt(string, initial value)
  • get_prompt prompt(click yes, 7)
  • Id comfirm(string)
  • Answer comfirm(the number is x)
  • alert (string)
  • alert (the answer is x)
  • document.write() // for web page output
Write a Comment
User Comments (0)
About PowerShow.com