COP2500 - PowerPoint PPT Presentation

1 / 25
About This Presentation
Title:

COP2500

Description:

document.write(' The result is ' result ' br '); result = x y; ... More Review Excercises. Create a FOR loop that displays numbers as: 10 9 8 7 6 5 4 3 2 1 ... – PowerPoint PPT presentation

Number of Views:48
Avg rating:5.0/5.0
Slides: 26
Provided by: soontharee
Learn more at: http://www.cs.ucf.edu
Category:

less

Transcript and Presenter's Notes

Title: COP2500


1
COP2500
  • Review
  • Room 188
  • Soontharee
  • soonthar_at_cs.ucf.edu

2
Operators
  • Arithmetic operators, -, , /, eq xy
  • Concatenation operatoreq correction
  • Comparison operatorsusing for the conditiongt,
    lt, , !, etc.

3
lthtmlgt ltheadgt lttitlegt Lab2
lt/titlegt lt/headgt ltbodygt ltscript
language"JavaScript"gt lt!-- Input variable
declaration--gt var x lt! Other variable
declaration--gt var y var z lt!--
Initialization --gt x 17 y 42
lt!-- Calculation --gt z x y lt!--
Output --gt lt! Text in ". " concatenate
with variable --gt document.write("X "
x "ltbrgt ")
document.write("Y " y "ltbrgt ")
document.write("Z " z
"ltbrgt") lt/scriptgt lt/bodygt lt/htmlgt
4
lthtmlgt ltheadgt lttitlegt Comparision
lt/titlegt lt/headgt ltbodygt ltscript
language"JavaScript"gt lt!-- variable
declaration--gt var x5 var y4
var result lt!-- Output --gt result x gt
y document.write(" The result is "
result "ltbrgt ") result
x lt y document.write(" The result is "
result "ltbrgt ")
lt/scriptgt lt/bodygt lt/htmlgt
5
Conditional
  • if/elseif (condition) statement-TRUEelse
    statement-False

6
lthtmlgt ltheadgt lttitlegt Comparision
lt/titlegt lt/headgt ltbodygt ltscript
language"JavaScript"gt lt!-- variable
declaration--gt var x5 var y4
var result lt!-- Processing --gt if ( x gt
y) document.write("x is larger.
ltbrgt ") else
document.write("y is larger. ltbrgt ")
lt/scriptgt lt/bodygt lt/htmlgt
7
lthtmlgt ltheadgt lttitlegt Comparision
lt/titlegt lt/headgt ltbodygt ltscript
language"JavaScript"gt lt!-- variable
declaration--gt var x5 var y4
var result lt!-- Processing --gt if ( x gt
y) document.write("x is larger.
ltbrgt ") else if ( x lt y)
document.write(y is larger. ltbrgt ")
else document.write(x
equal y. ltbrgt ")
lt/scriptgt lt/bodygt lt/htmlgt
8
ltscript language"JavaScript"gt lt! Input
declaration--gt var x,y,z lt!-- variable
declaration--gt var max lt! initialization
--gt x34 y10 z42 lt!--
Computation --gt if ( xgty) maxx
else maxy
if ( zgtmax) maxz
lt!-- Output --gt document.write(max
max"ltbrgt ") lt/scriptgt
9
Algorithm
10
ltscript language"JavaScript"gt lt! Input
declaration--gt var salary lt!-- variable
declaration--gt var taxrate1 var
taxrate2 var tax lt! initialization --gt
taxrate1 0.07 taxrate20.05
salary 1000 lt!-- Computation --gt if (
salary gt 1000) tax salary
taxrate1 else tax
salary taxrate2 lt!-- Output --gt
document.write("tax tax"ltbrgt ")
lt/scriptgt
11
Conditional (cont.)
  • if/else ifif (condition1) statement-condition
    1-TRUEelse if (condition2)
    statement-condition2-TRUEelse
    statement-False

12
lt!-- Computation --gt if ( NumGradegt89)
AlphGrade A else if (
NumGradegt79) AlphGrade B
else if ( NumGradegt69) AlphGrade
C else if ( NumGradegt59)
AlphGrade D else
AlphGrade F
13
Algorithm
14
ltscript language"JavaScript"gt lt! Input
declaration--gt var salary lt!-- variable
declaration--gt var taxrate1 var
taxrate2 var taxrate3 var tax lt!
initialization --gt taxrate1 0.07
taxrate20.05 taxrate30.03 salary
1000 lt!-- Computation --gt if ( salary gt
1000) tax salary taxrate1
else if ( salary gt 700) tax
salary taxrate2 else
tax salary taxrate3 lt!--
Output --gt document.write("tax tax"ltbrgt
") lt/scriptgt
15
Array declaration
  • var array_name new Array(length)

16
Algorithm
17
ltscript language"JavaScript"gt lt! Input
declaration--gt var salary lt!-- variable
declaration--gt var taxrate new Array(3)
var tax lt! initialization --gt var
taxrate0 0.07 var taxrate10.05
var taxrate20.03 var salary 1000
lt!-- Computation --gt if ( salary gt 1000)
tax salary taxrate0
else if ( salary gt 700) tax salary
taxrate1 else tax
salary taxrate2 lt!-- Output
--gt document.write("tax tax"ltbrgt ")
lt/scriptgt
18
For Loop (chapter 6)
  • for (initialize test incre./decr.)
  • statement(s)

19
lthtmlgt ltheadgt lttitlegt Looping Constructs
lt/titlegt lt/headgt ltbodygt ltscript
language"JavaScript"gt lt!-- variable
declaration--gt var x 0 lt!-- Processing
--gt for ( var i 0 i lt 10 i )
document.write("i" i )
document.write(" x" x ) x
x1 lt/scriptgt lt/bodygt lt/htmlgt

20
Math Object (chapter 9)
  • Advanced arithmetic calculation
  • Math.abs(Number)
  • Math.round(Number)
  • Math.random( )
  • etc.

21
lthtmlgt ltheadgt lttitlegt Math objects
lt/titlegt lt/headgt ltbodygt ltscript
language"JavaScript"gt lt!-- variable
declaration--gt var x -5 lt!-- Processing
--gt document.write("Absolute value of " x
"is " ) document.write( Math.abs(x) )
document.write(" ltbrgt " )
document.write(Show me the random number!! "
) document.write( Math.random( ) )
document.write(" ltbrgt " )
lt/scriptgt lt/bodygt lt/htmlgt
22
ltscript language"JavaScript"gt lt! Input
declaration--gt var list new Array(10)
lt!-- variable declaration--gt var sum
var i lt! initialization --gt for ( i
0 i lt 10 i ) listi
Math.random( ) 100 sum 0 lt!--
Computation --gt for ( i 0 i lt 10 i )
sum sum listi
document.write(" sum " sum ) lt/scriptgt
23
Algorithm
24
ltscript language"JavaScript"gt lt! Input
declaration--gt var begin var
last lt!-- variable declaration--gt var i
lt! initialization --gt var begin5
var last 16 lt!-- Computation --gt for (
i begin i ltlast i )
document.write("i" i )
document.write(" square root " Math.sqrt(i)
) lt/scriptgt
25
More Review Excercises
  • Create a FOR loop that displays numbers as 10 9
    8 7 6 5 4 3 2 1
  • Chapter 9 questions 6,11 (page198,199)
Write a Comment
User Comments (0)
About PowerShow.com