Title: COP2500
1COP2500
- Review
- Room 188
- Soontharee
- soonthar_at_cs.ucf.edu
2Operators
- Arithmetic operators, -, , /, eq xy
- Concatenation operatoreq correction
- Comparison operatorsusing for the conditiongt,
lt, , !, etc.
3lthtmlgt 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
4lthtmlgt 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
5Conditional
- if/elseif (condition) statement-TRUEelse
statement-False
6lthtmlgt 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
7lthtmlgt 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
8ltscript 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
9Algorithm
10ltscript 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
11Conditional (cont.)
- if/else ifif (condition1) statement-condition
1-TRUEelse if (condition2)
statement-condition2-TRUEelse
statement-False
12lt!-- Computation --gt if ( NumGradegt89)
AlphGrade A else if (
NumGradegt79) AlphGrade B
else if ( NumGradegt69) AlphGrade
C else if ( NumGradegt59)
AlphGrade D else
AlphGrade F
13Algorithm
14ltscript 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
15Array declaration
- var array_name new Array(length)
16Algorithm
17ltscript 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
18For Loop (chapter 6)
- for (initialize test incre./decr.)
- statement(s)
19lthtmlgt 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
20Math Object (chapter 9)
- Advanced arithmetic calculation
- Math.abs(Number)
- Math.round(Number)
- Math.random( )
- etc.
21lthtmlgt 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
22ltscript 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
23Algorithm
24ltscript 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
25More 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)