This document provides examples of JavaScript code snippets and explanations of JavaScript concepts like variables, functions, operators, and comparisons. It demonstrates assigning values to variables, performing mathematical operations, concatenating strings, and using comparison operators. Functions are defined and called to demonstrate passing parameters and returning values. Escape sequences and logical operators are also explained with examples.
Scaling API-first – The story of a global engineering organization
تعلم جافا سكربت
1.
2. -:
() *) + ! # ,- .,/) 0 1 2 %&&' ! quot; #$
Live Script
<= >?@ AB C D E F? *G quot; +,/G
-: , * @H *,G
!G I J,- 0? K
<SCRIPT>
--!>
<--//
<SCRIPT/>
B #G) # ! <SCRIPT> U V +K *,G *) ! 0 *W X YB
<SCRIPT/> # / * Z[
<--// --!> 0 ] +) 0 U )/ !, E F? I<F G)
-: )UAG * F ^ - G
!HAb K IV I_B ` #WK Ya? , ` ?<F - !G * !V @G<
Ya?B Ic
U V * a? K )d ! e G
-: # _B
<SCRIPT>
--!>
l(quot;* BX jA quot; ) GHB ! X# XV quot;)alert
<--//
<SCRIPT/>
3. * UV ` #WK m? Ya? , `K )d H- nH U# `G G1 H-
*+ G
*G) # ! nH *) ! VF?p B n @HG quot; BX- o
*) # ! #B qG e ) nH < ! *r?sH *,t E F?p o
*, p C
-: *W XB
_ ! B qG ? _B JAVA - (,GqK java p *u !
alert * F ` e G ) D +1 m #G+G1 alert .
quot;s, G { G | EK d?B DUV /* */ // * Z H-
<SCRIPT>
--!>
hhhhhhhhhhhhhhh*/
hhhhhh
/*hhhhhhh
l(quot;alert(quot;7azm
hhhhhhhhhhhh//
<--//
<SCRIPT/>
•s // YcK /* !#GHK */ +K 0 quot;s, G o
-: * ] quot; ,
p *u B ^j G) ^jp !V
break - do - function - null - typeof - case - else - if - return - var -
continue - export
import - switch - void - default - false - in - this - while - delete - for
- new - true - with
-: quot; uG
4. *B qG Ip Bquot; + 0jqK * CU 0 *_ +G K
p qG D• G) ŽB C!
*r qG K` B !H K m A +) 0 uG , `G K H-
uG ! * GAG
a +) uG
*A At quot; uGB ^ _B
JaVa
Ja_VA
java123
-: *“r < quot; uGB ^ _B
hhhh”
m88••
quot;varquot; * ] *, qG )p uGB ^ a
<SCRIPT>
--!>
lquot;var message=quot;first java
l(quot;alert(quot;message
<--//
<SCRIPT/>
-: quot; + ™?
*G * , - ! *+ t *u * _ p *u +G K
true 1 ^? * AI X a )jqK ?sK #K uGB 0
false
<SCRIPT>
--!>
5. var a=0.06
lquot;var b = quot;java script in easy steps
lvar c false
l(alert(typeof a + quot;nquot; + typeof b + quot;nquot; +typeof c
<--//
<SCRIPT/>
* FJ # G) * * aquot;Ÿquot; uGB ^ ?s) . _
()alert
# *t q quot; + ™?H * G¡ typeof qG G)
/ !* aI *t q quot; p q ¡ ?s) quot;+n/+quot; F? ?s)
)UAG Y B ! )p
-: Escape Sequences ?#EB
0 n! m C quot;/quot; *,] *r *BX- .+ K B H-
K¤ - ?“ B B ™? B *BX DUV Y+G) CU m A
pe 1 K B ^jp m A UV + G) F AB
mU -----------b/
m <F -----------f/
)p / -----------n/
™?p *BX------------r/
* p *BX-----------t/
* A *, , ^ #G J,- K DF EB +Ga *BX----------'/
* A *, , *) # J K *p jB +Ga *BX----------quot;/
D * E,< *r b--------//
^ # 0 F nH *, , I< F # BF .) r - #HB DF EG )
* E nH
8. la=str1
l:b=str2
lc=str3
l(alert(a+b+c
{
•] * X J,- C?GAK !G * () G _ UV ?s)
a ¤X J,- C?GA) 0 e ) # ^ - G C0 `U
* Jm B quot; -? B ¤X IsH ?s)
* * * * *
A B H #G
-: !K - 0? K d 0
* @H *,G * G1 *s) r ***
)UAG * F ^ - G ***
* quot; , ***
quot; uG ***
quot; + ™ ? ***
Escape Sequences ?#EB ***
***
•] ***
DF G ***
uG >q ***
•] ?F K ***
(: +- ^b0 !_
9. -: * Z ) Iu G quot;XB B
µ+ #c + * AI X • Y <==== +
¶ r <=== -
· c <=== *
* s <=== /
* s !a <=== %
* sY DF )d <=== ++
* s µE< > s <=== --
D ) AK K CU s * s µE< Y 0 B?s) -- ++
a=b*c-d%e/f; this is unclear
a(b*c)-((d%e)/f); this is clear
lvar addnum=20+30
lquot;var addstr =quot;lovequot;+quot;7azm
lvar sub=35.75-28.25
lvar mul=8*50
lvar mod=65%2
lvar inc=5;inc=++inc
lvar dec=5;dec=--dec
lquot;var result=quot;Addunm isquot;+addnum+quot;n
lquot;result +=quot;Addstr isquot;+addstr+quot;n
lquot;result +=quot;Sub isquot;+sub+quot;n
lquot;result +=quot;Mod isquot;+mod+quot;n
lquot;result +=quot;Mul isquot;+mul+quot;n
lquot;result +=quot;Inc isquot;+inc+quot;n
10. lquot;result +=quot;Dec isquot;+dec+quot;n
l(alert(result
-: * s/H Iu G quot;XB B
Logical AND <=== &&
Logical OR <=== ||
Logical NOT <=== !
a J,- C?GAK !G quot;XB YB * s/H Iu G quot;XB B qG K
false true *s s
false true J ?AGK 0 #H ) !G s
*At + Ÿ true * s¡ ?s) G a *At B .sAG ?sK &
G s G,1
false * a¡ ?s) & I u G IB B 0
G s B* a C *At + Ÿ true ¡ ?s) ||
D /< IB *A@ DF A * s nA +G< ŽK ¡ ?s) !
-: _B
J,- C?GA) JaVa! uG 0 true * a J,- C?GA) JaVa uG 01?
false * a
I1 ! * 1¼) UV !=JaVa ! G I #+G K 0 quot; s +/G Ic
*s uK G) D?/<
var a=true,b=false
var test1=(a&&a); //test both operands for true
l(var test2=(a&&b
l(var test3=(b&&b
var test4=(a||b); //test either operand for true
l(var test5=(a||b
l(var test6=(b||b
11. var test7=!a;var test8=!b; //invert values
quot;var result=quot;ANDn
lresult +=quot;1:quot;+test1+quot;2:quot;+test2+quot;3:quot;+test3
lquot;result +=quot;nnORn
lresult +=quot;4:quot;+test4+quot;5:quot;+test5+quot;6:quot;+test6
lresult +=quot;nn!n7:quot;+test7+quot;8:quot;+test8
l(alert(result
-: s G >q Iu G IB B
(=) I u G IB B
a=b _B
a=b *) * s
(+=) I u G IB B
a+=b _B
a=a+b *) * s
(-=) I u G IB B
a-=b _B
a=a-b *) * s
(*=) I u G IB B
a*=b _B
a=a*b *) * s
(/=) I u G IB B
a/=b _B
a=a/b *) * s
(%=) I u G IB B
12. a%=b _B
a=a%b *) * s
-=: _B
var a=quot;JavaScriptquot;, b=quot;codequot;; //assign string values
a+=b; //concatenate strings and assign to
a var c=8,d=4; //assign integer values
c+=d; //add numbers and assign result to
c var e=7.5,f=2.25; //assign float values
e-=f; //subtract f from e and assign result to
e var g=8,h=4; //assign integer values
g*=h; //multiply numbers and assign result to
g var i=8,j=4; //assign integer values
i/=j; //divide i by j and assign result to
i var k=8,I=4; //assign integer values
k%=I; //divide K by I and assign result to
-=: * s *t q I u G quot;XB B
C G D H B ==
C G - D H B =!
B +1 D H B >
B Ia D H B <
C ) B +1 D H B =>
C ) B Ia D H B =<
-=: _B
l(quot;var teststrings1=(quot;JavaScriptquot;==quot;JavaScript
13. l(quot;var teststrings2=(quot;JavaScriptquot;==quot;javaScript
l(var teststrings1=(1.78==1.78
l(var teststrings2=(1.78!=1.78
l(var teststrings1=(15<15
l(var teststrings2=(15>15
-=: *W XB
_B ? - (,Gq) IG+ quot;, * s H-
l(quot;var teststrings1=(quot;JavaScriptquot;==quot;JavaScript
s /GB # *A At D +- DUV
l(quot;var teststrings2=(quot;JavaScriptquot;==quot;javaScript
+1 JK J ! (J) !p m mXG< ! e+ *“r < D +- DUV
ut * _ !
-=: !r Iu G IB B
IcE * s IB B ?V +G )
true * G¡- V /< #GAt quot; + *F !r b +G< ?s)
false
+G< * GH s+r H D +- U EHG ?s)
-=: ?V DU# > q e 1 G
ltest expression)?if true do this: if false do this)
B e) ¿E@G *t q *u, F I u K B IB UV `H )
) AK ŽB . ) CU
¿E@G
var browser=browserID;//Internet Explore or Netscape
l()browser==quot;IEquot;)?greetIEuser():greetNNuser)
14. ************************************************
WG )p F! 1 s, ^b0 !_ !#GH) HV J
*HB EG K ?p 2_
-=: * r if +-
-: #G+ 1 K
lif(test expression)statement to execulte when true
/ _B
var msg,num
lnum=7
}(if(num%2!=0
lquot;.msg=quot;This is an odd number
l(alert(msg
{
* s 1Ÿ ) AG (%) * s !a IB B +G< G) . _
num uG ! DF?p?
À J,- * s I+sK
qG CF a 0 B 1 G, . e1 G qG ***
(num(%2==1
if > q B ¿Z?) _B
lvar username=null
}(if(username==null
l(quot;quot;Áquot;username=prompt(quot;please Enter Your Name
l(if(username!=quot;quot;)alert(quot;welcomquot;+username
15. {
` ?<F `HB e,/) Y B ` #W) m? . _ UEHK B H-
e K D +- ` eG ) ` Ÿ
*G,<F CU
-=: if-else * B+ quot; +
!r sG c) m )
lif(test expression)do this;else do this
else * ,1 I+a *r?sHB *,t F?p B o
lvar num=2,bool=false
l(if(num==1&&bool==1)alert(quot;TEST1 bool:quot;+bool
else
l(if(num==2&&bool==1)alert(quot;TEST2 bool:quot;+bool
else
l(if(num==2&&bool==0)alert(quot;TEST3 bool:quot;+bool
else
l(if(num==3&&bool==0)alert(quot;TEST4 bool:quot;+bool
-=: switch { B+ +
* KH * s YB ]XG) ?H- sK Â *At B .sAG ?sK
0 ?H ) AK ! case * ] *, qG K
!Z G F? ) AK ! default * ] *, qG K
break * , 0 ?H F?1 *) # 0? K 0 e )
lvar num=2
16. }(switch(num
lcase 1:alert(quot;This is case 1 codequot;);break
lcase 2:alert(quot;This is case 2 codequot;);break
lcase 3:alert(quot;This is case 3 codequot;);break
l(quot;default:alert(quot;This is default code
{
-=: for G W
*G+ 1 K
lfor(initializer,test,increment)statement
F -· A >q F , *) + * a ) AK ! initializer qG )
Gquot;B
quot;iquot; * ,- .,/) * 1¡ u U# uG qG )a !
(a?GK *“r < 0? K B H- G ) *A At 0? K B H-
F )j) F I1
lvar a=0,b=0
}(++for(var i=0; i<5; i
la+=10;b+=5
{
l(alert(quot;FOR LOOPnn A isquot;+a+quot;...B isquot;+b
-=: For-In G W
lquot;quot;=var i=0;a
}(or(property in window
lquot;...quot;+a+=property
{
17. l(alert(a
-=: while G W
/< * s ¡ - 0 I@) 0 J +G< G)
/*/*/*/ )UAK
¿E@G B K nH ²XÄ !] # X G W ?s)
lvar i=0,num=50
}(while(i<15
l--num
l++i
{
l(alert(quot;LOOP stopped atquot; +i+ quot;nnum is nowquot; +num
-=: Do-While G W
G W J,- K do * ] *, qG K
*“r < * GH ¿+@K JG G F G K
lvar i=0,num=50
}do
l--num
l++i
l(while(i<1{
l(alert(quot;LOOP stopped atquot; +i+ quot;nnum is nowquot; +num
-=: Break * B+ +
lvar i=0
}(while(i<6
lif(i==3) break
19. lquot;city.value= quot;ksa
{
*****************************************************
- J,- H) 0 JH K
*, t?K ! *s a 0?1
!K AK ?,+sK
*K 1 * ,- X
*+A) 1) Hs * e+ ! < G J,- p(
JZ )
F %” VF - !G FI FD - H ,- !s
-=: ? Y +
******************************************************
****
-=: quot; ?E@ ^
new * ] *, qG K * ?E@B * J,- uG YB IB G G)
()Array ^J H YB p *u !
) AG * ?E@ !quot; + B DF GB ™ ? ) AK )
E@ +) CU #E a * ?E@
()var a=new Array
lquot;a[0]=quot;First
lquot;a[1]=quot;JavaScript
lquot;a[2]=quot;Array
+G ) a E@ @H B #E 0 o X 0
2_ @H +G ) H a !_ @H
21. lvar arraysize=a.length
(lalert(a[0]+a[1]+a[2]+quot;nNo.of elements isquot;+arraysize
-=: * ?E@ t H- J a <F G W qG
lquot;var str=quot;FILL ELEMENTS LOOPnn
l()var arr=new Array
}(++for (var i=0;i<8;i
lquot;arr[i]=quot;Number isquot;+i+quot;n
l[str +=arr[i
{
l(alert(str
-=: t H B )j *Z
array.length * t q qG !, E #E a*Z
* a J,- C?GA) CU ! G @H , ” ¿ A@ a K ¿Z?) _
a * ?E !
l(var a=new Array(1,2,3
a[a.length]=4 //a.length is 3
l(var b=new Array(5,6,7
}(++for(var i=0;i<b.length;i
[a[a.length]=b[i
{
l(()alert(a.concat
-=: t H *t q m I X
22. B *-? B J * ?E@ t H- Y p I)?AG ?sK ()array.join
* AIX
*Z G *,t E, I) It ) AG C G< • ? I+sK 0 )
l()var a=new Array
lquot;a[0]=quot;It
lquot;a[1]=quot;isn't
lquot;a[2]=quot;rocket
lquot;-a[3]=quot;science
lquot;a[4]=quot;it's
lquot;a[5]=quot;just
lquot;a[6]=quot;Java
l((quot;quot;)alert(a.join
-=: @H >q eK G É -
* @H *,G B ^jp UV 0 1 ?
l(quot;var imgs=new Array(quot;img1.gifquot;,quot;img2.gifquot;,quot;img3.gif
img3.gif-img2.gif-img1.gif ?V HV ¿ A@ ŽK H
img1.gif-img2.gif-img3.gif É
// _B
l(quot;var imgs=new Array(quot;img1.gifquot;,quot;img2.gifquot;,quot;img3.gif
lvar rev=false
....slideshow routine is displaying the final image so//
lrev = true
}(if(rev==true
l()imgs.reverse
23. rev=false;} //remember to reset the test variable
l(quot;-quot;alert(imgs.join
-=: * - E quot; ?E@
* A * ?E@ B D ) p * ?E@B I - ! qG K ()array.slice
// _B
l(var a=new Array(1,2,3,4,5,6,7,8
l(var b=a.slcie(2,5
l(var c=a.slice(1,-1
l(var d=a.slice(3
-=: * ?E@ t H- e K K
* AI X tH *t q s eK G qG K ()array.sort
*) *s) /
// _B
l(var integers=new Array(3,8,1,9,7,5,4,2,6
l(integers.sort(); var floats=new Array(0.5,0.125,0.57,0.25
l(quot;floats.sort(); var strings=new Array(quot;7azmquot;,quot;mohammadquot;,quot;ali
l()strings.sort
lquot;var str=quot;SORT
lquot;-quot;str +=quot;nnIntegers array isquot;+integers.join
lquot;-quot;str +=quot;nnFloats array isquot;+floats.join
lquot;-quot;str +=quot;nnStrings array isquot;+strings.join
l(alert(str
?@ *t q I AG quot; , # G ! * ?E@ qG
-=: #Z G
24. <SCRIPT>
--!>
l(quot;var pics=new Array(quot;pic1.gifquot;,quot;pic2.gifquot;,quot;pic3.gif
l()var preload=new Array
}(++for(var i=0;i<pics.length;i
l()preload[i]=new Image
[preload[i].src=pics[i
{
<--//
<SCRIPT/>
DjV p 0? K JG ?t ¤X I AK qG . _
?@ *V ! GG ¡ >q G Iu K H-
?@ (, > q 0 ?H J,- C?GAK J * ?E@
*K 1 * ,- X
ÉB q +
********************************
*******************************
-=: qG Bd YB e HG) Ì) G a? ) AK
B p *u ! #B qG G) )U, Ì) G a? F AG)
> q ŽB +
(c WH ! )F?p? )?sG *-
e) WH *- *t q quot; B?, J,- ?@A `H )!
25. date ]1^ nH ?s) 0
l()var now=new Date
l(alert(now
(-: # W V ?#$ * E 1 ¿Z?K D ?t . m?
-=: Ì) G *t q quot; B?,
+ B *) *, , B* s1 ? ¡ ?sK date.getDay
Et * s Saturday
friday * Í* s JG
U V !H )
Et * s U< ) +
* s U< )
H* s U< ) H
¤X * s U< ) ^ X_
* * s U< ) ^
* <* s U< ) É q
F * s U< ) *
B *) *, , B* s1 # ¡ ?sK date.getMonth
Et * s U< K january
%% * s U< K december
l(quot;var days=new Array(quot;satquot;,quot;sunquot;,quot;monquot;,quot;tuequot;,quot;wedquot;,quot;thuquot;,quot;fri
var mons=new
Array(quot;janquot;,quot;febquot;,quot;marquot;,quot;aprquot;,quot;mayquot;,quot;junquot;,quot;julquot;,quot;augquot;,quot;sepquot;,quot;octquot;,quot;n
l(quot;ovquot;,quot;dec
l()var now=new Date
l()var yy=now.getYear
26. l[var mm=now.getMonth();mm=mons[mm
l()var dd=now.getDate
l[var dy=now.getDay(); dy=days[dy
l(alert(dy+quot;quot;+dd+quot;quot;+mm+quot;quot;+yy
I1 o ` U ·?,,/ UEH) * @H *G, !• /< C *W XB
m Ao *G G a ?a
* ]XB ^ /< B *+G
-=: a? *t q quot; B?,
l()var now=new Date
l()var hh=now.getHours
l()var mn=now.getMinutes
l()var ss=now.getSeconds
l()var ms=now.getMilliseconds
lquot;var hi=quot;Good Morning
lquot;if(hh>11)hi=quot;Good Afternoon
lquot;if(hh>17)hi=quot;Good Evening
lquot;var tim=hi+quot;n
lquot;tim+=quot;Hours:quot;+hh+quot;n
lquot;tim+=quot;Minutes:quot;+mn+quot;n
lquot;tim+=quot;Seconds:quot;+ss+quot;n
l(alert(tim
-=: ! A a?G
Ì) G *t q quot; H] B H * s, qG K ()date.getTime
D) *H B
27. l()var start = new Date
l()var msec1=start.getTime
lvar num=0
}(++for(var i=0;i<250000;i
l++num
{
l()var stop=new Date
l()var msec2=stop.getTime
lvar diff=(msec2-msec1)/1000
l(quot;alert(quot;Time elapsed:quot;+diff+quot;seconds
*****
B G quot; B F - I ,sG a netscape `AE@GB 0 1 Ÿ // *W XB
'ÊÊÊ J À'ÊÊÊÊ
*****
-=: Universal Time Clock J,- m G
ÏGH) p •< a?K ! a?G * _ Universal Time +G )
l()var now=new Date
l()var hh=now.getHours
l()var mn=now.getMinutes
if(mn<=9)mn=quot;0quot;+mn
l()var ss=now.getSeconds
l()var utc_hh=now.getUTCHours
lquot;var wet=quot;athens time:quot;+hh+quot;:quot;+mn+quot;:quot;+ss+quot;nn
28. lvar utc=quot;Universal time:quot;+utc_hh+quot;:quot;+mn+quot;:quot;+ss
l(alert(wet+utc
! · u, !,A a?G ^ - G _ ?s)
***
a - D +- 0? G * s0 D - B Ia .] a 1 Ÿ / *W XB
# Et * Z ?s * B+ n0 `U
***
-=: * HBj *s/H
# ! GH) !G * HBj *s/H F AK 0 p *u, )
X< B qG
date.getTimeOffest * HsG
l()var now=new Date
l()var offset=now.getTimezoneOffset
lvar msg
}(switch(offset
lcase 240:msg=quot;East Coastquot;;break
lcase 300:msg=quot;Centralquot;;break
lcase 360:msg=quot;Mountainquot;;break
lcase 420:msg=quot;Pacificquot;;break
lquot;default:msg=quot;all
{
l(quot;.alert(quot;Welcome toquot;+msg+quot;visitors
-=: a? Ì) G ) AG a <F
l()var now=new Date
29. lquot;var orig=quot;Original:nquot;+now.toString()+quot;nn
l(now.setDate(21
l(now.setMonth(1
l(now.setHours(12
l(now.setMinutes(30
l(now.setSeconds(15
l(now.setFullYear(2005
lvar mod=quot;Modified:nquot;+now
l(alert(orig+mod
****
* *, , - D +- * a¡ ?sK toString
****
-=: date ] *t q s )jqK ·?,
#,)?AG ?sK * I X J s I)?AG ?sK date.toGMTString
GMT * HBj *s/H J
l()var now=new Date
lquot;VAR jpn=quot;Tokyo time:nquot;+now.toString()+quot;nn
l()VAR gmt=quot;UTC time:nquot;+now.toGMTString
l(alert(jpn+gmt
-=: WH {- qG
()setTimeout * HsK YB #B qG ) WH *-
? Y B ¡ - Ip B * HsK qG ?sK ()window.setTimeout
!? - J I@K D G ! )UAG
30. lvar num=0
}()function annoy
l++num
l(alert(quot;This is 10-Second Message No:quot;+num
l(window.setTimeout(quot;annoy()quot;,10000
{
l()annoy
-=: !HBj a¼ ^u
lvar num=0,tim
}()function advise
l++num
}(if(num==3
l(alert(quot;Ok-Itold you twicequot;); window.clearTimeout(tim
}else{
l(alert(quot;This is 10-Second Message No:quot;+num
{l(tim=window.setTimeout(quot;advise()quot;,10000
{
l()advise
-=: clock ! p W* V
<HTML>
<quot;()BODY ONLOAD=quot;tick>
31. <SCRIPT>
--!>
}()function tick
l()var now=new Date
lvar hh=now.getHours(); if(hh<=9)hh=quot;0quot;+hh
lvar mn=now.getMinutes(); if(mn<=9)mn=quot;0quot;+mn
lvar ss=now.getSeconds(); if(ss<=9)ss=quot;0quot;+ss
lvar tt=hh+quot;:quot;+mn+quot;:quot;+ss; document.f.clock.value=tt
l(window.setTimeout(quot;tick()quot;,1000
{
<--//
<SCRIPT/>
<quot;FORM NAME=quot;f>
<quot;INPUT NAME=quot;clockquot;TYPE=quot;textquot;SIZE=quot;10>
<FORM/>
<BODY/>
<HTML/>
_ U# ¿ Z?K * _ D ?@ J W
****
Z ) *+A) 1) Hs ?)
0 B I1 ! )V H ?< @
BÑ #,
1?<
32. CjH F?
HMA2003H911@YAHOO.COM
F B F ! =+
s B F - J,- p {u ! Math ] 1 C?GA)
*[ bÓ I # G {G _ { s {Z)
! {p {G _ s DUV J [ bÓ ! + m Ô qG K
-=:
(: Ä * ¡Ä B •s
++ 0F (, * _* ! *a ?a m?
(-: * ,- ™Xr
p *u, *t q quot; s +/K ! •s Math ] ! ?_ qG K
-=: PI _ qG
* quot; K D pquot; B^ Math.PI _ ?s)
var pos=new Array(); //array for position data
var xos=30,yos=30; //xy coordinate offsets
var rad=40; //radius of circle
}()function init
}(++for(var i=0;i<4;i
pos[i]+=Math.PI/45; //increment degrees
l(([var x=xos+(rad*Math.cos(pos[i
l(([var y=yos+(rad*Math.sin(pos[i
l(if(document.layers)document.layers[quot;lyrquot;+i].moveTo(x,y
(if(document.all
33. l(quot;eval(quot;lyrquot;+i+quot;.style.top=x;lyrquot;+i+quot;.style.left=y
{
l(setTimeout(quot;spin()quot;,100
{
Math ] quot; HsK *-? B B +G K Math.sin Math.cos * HsK
-=: Math ] *t q quot; HsG
(( (-: YB )) ! _ F !. !_ J W
-=: a e) sK
*BX- J,- I K !G F - e) sK ! Math.round * HsK qG K
*) -
*,)?/ *) F- c) ¿ At a · a J I@K 2 A
@a F - J
-=: _B
lvar a=7.5
l(a=Math.round(a
lquot;a=quot;Rounded positive:quot;+a+quot;n
lvar b=-7.5
l(b=Math.round(b
lquot;b=quot;Rounded Negative:quot;+b+quot;n
lvar c=3.764638467915
c=c*100 //take it up two places
c=Math.round(c); //do the round
34. c/=100; //take it back down 2 places
lc=quot;Commuted Long Float:quot;+c
l(alert(a+b+c
****
*HB Ia CU I *HB +1 CU J * s) e a // *W XB
Õ- ?V #+) sK ÕÖ'- e) sK F . _ !
****
-=: *+p? *+ a e) sK
+1 J C a e) sK J,- - K * HsK !V Math.ceil * HsK
¿ At a
ut J C a e) sK J,- - K * HsK !V Math.floor * HsK
¿ At a
lvar a=7.5
l(var a1=quot;a1:quot;+Math.ceil(a
l(var a2=quot;a2:quot;+Math.floor(a
lvar b=-7.5
l(b=Math.round(b
l(var b1=quot;b1:quot;+Math.ceil(b
l(var b2=quot;b2:quot;+Math.floor(b
lquot;var rup=quot;ROUNDING UPnquot;+a1+quot;nquot;+b1+quot;nn
lvar rdn=quot;ROUNDING DOWNnquot;+a2+quot;nquot;+b2
l(alert(rup+rdn
***
E@ J I@) e) sG 0 ¿ At a · a J *+ s e) sK H-
***
35. -=: a * sB
* s¡ ?sK / ?1 G a* s ?sK Math.max * HsG
+1
G s ²E H !
G s Ia ¡ ?sK #H *s ÉE Math.min * HsG
* s , *+ B* B a^ qG K Math.pow
l(var sq=Math.pow(5,2
l(var cb=Math.pow(3,3
l(var hi=quot;Round up:quot;+Math.max(sq,cb
l(var lo=quot;Round Down:quot;+Math.min(sq,cb
l(var ng=quot;Round Negative Up:quot;+Math.max(-5,-4.75
l(alert(quot;MAXMINnnquot;+hi+quot;nquot;+lo+quot;nquot;+ng
- =: ]? - )F - * s @
?@AB C - a - D +- * a¡ qG K Math.random * HsK
ÊÖ% ÊÖÊ
”· c 01 Ÿ
”ÖÊ ÊÖÊ ¶ G) !] ? - a^ J,- I
Math.ceil qG e) sG ! eÄ K H1 Ÿ
l()var rand1=Math.random
lvar rand2=rand1*10
l(var rand3=math.ceil(rand3
l(var another=Math.ceil(Math.random()*10
-=: * ] ? a
37. ! pic * a ) AK Html *t q img j B G *BX- X< B`Ÿ G)
scr *
var pix=new
Array(quot;pic0.gifquot;,quot;pic1.gifquot;,quot;pic2.gifquot;,quot;pic3.gifquot;,quot;pic4.gifquot;,quot;pic51.gifquot;,quot;
l(quot;pic6.gif
l(var rand=Math.floor(Math.random()*7
l[document.images.pic.scr=pix[rand
l([document.write(rand+quot;:quot;+pix[rand
***************************************
* s+G WG F B H #G
JaVa-ScRipT F? -=: 1?<
hma2003h911@yahoo.com
Math p
* ,- )B _
G) Ä?, =e _ Math.E
*G a Ø,+K CU ! +/
ÀÖÕ%•À• +) sK
ÀF ! +/ G) Ä?, Math.LN2
F ! +/ G) Ä?, Math.LN10
%Ê
À Ô G) Ä?, Math.LOG2E
e _,
10 Ô G) Ä?, Math.LOG10E
e _,
pi _ Math.PI
U,{ ? {s Math.SQRT1_2
À Ú! G
38. À Ú! G U Math.SQRT2
-: Math ] {t q quot; HsG
!_
{s,/ { s ¡- Math.abs()
ep - +- ŽK H 0? ) Math.acos()
{) j K
ep - +- ŽK H 0? ) Math.asin()
{) j
I$ - +- ŽK H 0? ) Math.atan()
{) j
x ?A B {) j Is Math.atan2()
{/s J [
ep?B F - · aÔ e) sG Math.ceil()
Ke p* a¡ ?s) Math.cos()
{) j
e =- +- ŽK H Math.exp()
e F - · aÔ e) sG Math.floor()
! +/ G) Ä?, Math.log()
+1= - +- ŽK H Math.max()
)F
ut= - +- ŽK H Math.min()
)F
s * a¡ ?sK Math.pow()
a - +- ŽK H Math.random()
!] ? -
¿ At F - · aÔ e) sG Math.round()
ep* a¡ ?sK Math.sin()
{) j
U - +- ŽK H Math.sqrt()
! G
{) j I$ - +- ŽK H Math.tan()
39. *K 1 * ,- X
quot; +G< ·+ `Ÿ ! C <G UG-
Y ! +
-=:
************************************************
-=: * AI X b=
*p Fj +Ga quot; BX- F?p? j GK B DF -
lquot;var a= quot;JavaScript Strings
l(alert(a.length
array.length * t < * s _ ?s)
string.length * t <
************
D +1 m # J,- quot; YB IB G G)
************
-=: * AI X quot;?B
Db )m *_ @H- I1 0? ) quot; ?E@B * _ +G K
* WH * ?E@ t H- J # ) !G *s) / ÉEH *
()string.chartAt * t q qG m DUV J,- ?_ `H )
# ><• ?1 @H # a YB IB GK !G
lquot;quot;=var str=quot;linger inquot;,newstr
l(var a=quot;First letter:quot;+str.charAt(0
l(var z=quot;Final letter:quot;+str.charAt(str.length-1
}(++for(var i=0;i<str.length;i
40. l(if(str.charAt(i)!=quot;iquot;)newstr+=str.charAt(i
quot;else newstr+=quot;o
{
lquot;var result=quot;STRINGSnn
lquot;result +=quot;New string:quot;+newstr+quot;n
l(alert(result+a+quot;nquot;+z
-=: * AI X •
² / J,- qG )* A X • ! quot;+quot; IB qG )
> q F? !Y
lvar num=99
lvar flt=98.6
lvar bool=true
lquot;var str1=quot;Although
lquot;quot;var str2=quot;F is cited as quot;body temperatrue
lquot;var str3=quot;nthe
lquot;var str4quot;range is from about 97 to
lquot;.var str5=quot;F
l(alert(str1+flt+str2+str3+bool+str4+num+str5
-=: * *, , I< F Bm - 2A+
m C - 2A+ ! qG K string.index * t q qG
• ?1 #H K G) * - * *, ,
mA * F ) YZ?B ¡ * HsG ?sK . /G ¤ * !
* A *, , ./
41. G) !G * A *, , I< F * - E * A *, , ./
#H- 2A+
%- * s¡ ?sK . * HsG 0 . /G B ™? C ¤ A) Ÿ
I< F @ m A ` U1 •sH - 2A+, string.indexOf * t q qG K
* A *, ,
#GAt B 1G m # ! G )+ *t q
lquot;var str=quot;mailme@domain.com
l(quot;@quot;)var att=str.indexOf
l(quot;.quot;)var dot=str.indexOf
l(quot;#quot;)var hsh=str.indexOf
lquot;var fmt=((att!=-1)&&(dot!=-1))?quot;validquot;:quot;invalid
lvar res=quot;Format isquot; +fmt
res +=quot;n@ atquot; +att
res +=quot;nDot atquot; +dot
res +=quot;nnHash isquot; +hsh
l(alert(res
-=: D ?* A *, , sK
string.split * HsK qG * A *, , quot; ? B I@ G)
lquot;var str=quot;JavaScript in easy steps
'(quot;quot;)var ss=str.split
lquot;var bk=quot;JavaScript in easy steps|Mike McGrath|$9.99
l(quot;|quot;)var bks=bk.split
l[var res=quot;Topic :quot; +ss[0
l[res +=quot;nTitle :quot; +bks[0
l[res +=quot;nAuthor :quot; +bks[1
42. l[res +=quot;nPrice :quot; +bks[2
l(alert(res
-=: * - E * AI X
* A* A *, , B* - * *, , J,- ?@A `H )
string.substring * HsG qG
*, , , *) #H *) + YZ ?B ) AG / J,- C?GAK 0 e ) !G
* ,t * A *, , I< F * ?,/ D) * A
qG * ,t *, , B* - E * A *, , ¡ - `H )
string.substr * HsG
lquot;var str=quot;JavaScript in easy steps
(var sub1=str.substring(14,19)+str.substring(0.11
l(var sub2=str.substr(14,5)+str.substr(0.10
lvar res=quot;Substring method :quot; +sub1
lres +=quot;nSubstr method :quot; +sub2
l(alert(res
-=: * AI X J uG
I X Jquot; + B Ý < ™ ? I)?AG ?sK ()object.toString
# X< B *
* A *, , ¡- ] F #HB m # * * DUV +G K
* E ] UV ) ? JG *H- X G K CU ] *t q
* *, , *_
p *u, ·?G B n C ! * HsG DUV qG `H ) 1
] ., GK !G quot; B?, µ -( Ip B
44. l(var res=quot;Integer :quot; +parseInt(str
l(var res=quot;nFloat :quot; +parseFloat(str
lquot;var badstr=quot;PASS RATE66.6%
l(res +=quot;nNon-numeric :quot;+parseInt(badstr
lquot;: res +=quot;nFound
lquot;res +=isNaN(parseInt(badstr))?quot;Characterquot;:quot;Number
l(alert(res
-=: * AI X !quot; uG a¡ -
CU F? J,- C?GAK * *, , - D +- • G ?sK ()eval
p *u, *G G1 K
D /< *GA@ ) sG *HB .sAG F
lquot;var inputname=quot;textfield
lquot;quot;var inputtext=quot;quot;JavaScript Text
l(quot;eval(document.forms[0].quot;+inputname+quot;.value=quot;+inputtext
-=: * AI X , F ?1 { G1
I< F m I # K * HsG DUV e,/GK ()string.ChartCodeAt
# • ?1 *, ,
?@A B `H K *s É - * HsG DUV ()string.fromChar Code
? F? Bm J,-
lquot;var str=quot;Code Fun
lquot;quot;=var enc
lquot;quot;=var unc
}(++for(var i=0;i< str.length;i
45. lquot;Áquot;+(enc += str.charCodeAt(i
{
l(quot;Áquot;)var ss=enc.split
}(++for(var i=0;i< ss.length;i
l([unc +=String.fromCharCode(ss[i
{
l(alert(quot;Encoded:quot;+enc+quot;nUnencoded:quot;+unc
***************************************************
******************************************************
********
******************************************************
****************
Y *) # J I@ HV J
!a WG K a 0?1 0 ?p
*B quot; +G< e+ < G J,- U-
1?< !K AK
CjH F?
hma2003h911@yahoo.com
*K 1 * ,- X
q G - I1
I cE # UV ! ^ - / ,! H,V H ?< ? HK
F %” VF - !G FI F {G H ,- !s
-=: ? B_ +
46. ************************************
-=: ] Þ HB
new { ] {, X< B { ?# ) p {@@qB quot; H] 1 ^ )
()Object Þ H p *u !
n] @< ¤X ) AG ?s) car )p ]1^ ?s) ! G _
F AB aquot;Ÿ ] U#
l()var car=new Objcet
lquot;car.maker=quot;Porsche
lquot;car.model=quot;Boxster
lquot;car.color=quot;Red
l(alert(car.color+quot;quot;+car.maker+quot;quot;+car.model
***
new Objcet p ? * B F?p o
***
! *tq )p ] 1 ) AK { E 1 HG ?s) < _B
*+ G n] @q ¡ - ) ( 1 n@qB 0 ]1
l()var mondeo=new Object
lquot;mondeo.badge=quot;Mondeo
lquot;mondeo.body=quot;Saloon
lmondeo.doors=4
lquot;mondeo.color=quot;Red
lquot;mondeo.engine=quot;1.8litre
l()var car=new Objcet
lquot;car.maker=quot;Ford
lcar.model=mondeo
l(alert(car.maker+quot;quot;+car.model.badge+quot;quot;+car.model.body
47. DOM > q I , G
B {-? B ¿E@GB C ! (Document Object Model(DOM )
! quot; H]
J,- G Ip B p X< B #Z - ) ¿E@G UV
HTML *u, D• K CU HG ^F
tH B { ?E@B J,- I G K 0 #H ) JG n] @< DOM `,G K
YB []images I_B e)? !
?s CU document ] 1 ! * t q1 []document.images
e)? {AEt ! F?p?B ?t I1 0 ?H- )jqG
{u, *G G1 K CU F? !J ?@ > q 0 ?H )jqK G)
I< F html
?@ > q 0 ?H )jqK G) [document.images[0 * ?E@
# ! * GG
D ) jG * ?E@ *t q tH
¿E@G quot; F sB * _ DOM +G )
DOM - (,GqK Netscape DOM ` U
_B
document.bgColor * t q, * a G _ UV ?s)
lquot;document.bgColor = quot;black
***
^ F? ¿+t * E,q 0 Ý K m? . F? , |U EHK H-
***
***
self.bgColor I_B window ¡ self e 1 K qG `H )
***
-=: {AE@ quot; H] 1 ¡ G
49. Netscape · H > < ?V - Y+G EG
****
-=: ¿E@G J,- m G
* B H) quot; ¼ Iu G document ] J D ) p n] @< * Z
dhtml !
document.layers * t < B a Netscape *1 b
document.all * t < ^ Microsoft ? ) B {1 b H
™? J,- m G Ip B n] @q DUV nAE ?sK 0 Ic B
*G J,- *K a B 1 G ¿E@G
dhtml *u,
¿E@G *t q {AE@ ¿G ¿E@G quot; F +G< ! G _ ?s)
*_) A ¿E@G quot; F s+r
*AE@ Microsoft *1 b Netscape {1 *t q * ) s
*) *t q * Z G
Ý < ¿E@K quot; F
lquot;if(document.all)window.location = quot;ie-dhtml.html
lquot;if(document.layers)window.location = quot;nn-dhtml.html
} else
var oldnn = (navigator.appName == quot;Netscapequot;&&
l(parseInt(navigator.appVersion)<4
{ lquot;location = (oldnn) ? quot;nn-old.htmlquot; : quot;default.html
{
-=: I u G W nA
*B qG ²/ Ý *_ active x *t q AG quot; F +G K
!
e)? quot; J,- {#p ? quot; ^
DF AK CU I u G WH s+r nH B/ {G Fs _ ?s)
50. lquot;if(navigator.platform == quot;Win16quot;)var os=quot;Windows3.1
lquot;if(navigator.platform == quot;Macquot;)os=quot;MacOS
lquot;if(navigator.platform == quot;Win32quot;)os=quot;Windows95
l(document.write(quot;Operating system isquot; +os
-=: Schockwave ŽB
0 B 01 Ÿ B* nA +G< * , p *u ?sK a
qG
0 1 Ÿ *,) {AEt *) I AK Flash Macromedia ,¡ ?s) 0
Schockwave ŽB
¶ GB Ä
e H *t q ¿E@G quot; F ! navigator.plugin qG )
B
) *s) / DUV SchockKwave ßX ! B J,- ?@A Ip
# -K
?,+ 1 G ¿E@GB ! IB 1 I
s+r F A {AE@ I AG ?s) nAE * , !G _ ?s)
{ GH,
quot;if((navigator.appName == quot;Microsoft Internet Explorer
navigator.appVersion.indexOf(quot;Macquot;) ==-1&&
(navigator.appVersion.indexOf(quot;3.1quot;) == -1&&
||
([quot;navigator.plugins&&navigator.plugins[quot;Shockwave Flash)
navigator.pulgins[quot;Shockwave Flash 2.0quot;]) window.location = ||
lquot;quot;playflash.html
else
51. lquot;window.location = quot;noflash.html
-=: Java p *u ! ^ /< YB IB G ·?,
{ HsK X< B p *u qG ¿E@G ^ E1 Ý?G B sK )
()navigator.javaEnabled
{“r < 1 {A At * H ?+ * s¡
!# ` U * t<F B navigator ] {t < * HsK * _ +G K
?a *-?+GB 0? K 0 e )
_B
(()if(navigator.javaEnabled
lquot;window.location = quot;javapage.html
else
lquot;window.location = quot;nonjavapage.html
*********************
******************************************
******************************************************
*********
******************************************************
******************************
*G+G1 ! Y G YZ m? e) a - B_ J#G
p I ,a * ,- !a 0 *G, 1 B É
*,“ # e,/ 0?, )U 0 ?< Y p b
G ) 0 cB ?s) B I cE # UV ! 1) H, p
I cE # UV ! ^ - / , B ?< ? HK
CjH F? 1?<
52. hma2003h911@hotmail.com
*K 1 { ,- X
p F BY G UV
1 Z J,- H) 0 ?p
---*---*---*---*---*---*---*---
-=: 1G {, -
window ] * K * HsK * _ ()alert * t < +G K
!K 1 #G G1 )
()window.alert
Gt q G HsG ! J * HsG * _ window.confirm * HsK +G K
window ]
J,- ?@A, #B qG ) #] - G H- * @ quot; B¡ K !G
qG B 1K
d true ¡ ?s) CU ok . ?B d J,- C?GA) CU ?A Y B !
?s) CU cancel
! B + nH, false ¡
_B
l(quot;àvar ask = comfirm(quot;Do you wish to proceed
lvar msg
lquot;if(ask)msg=quot;OK button was pushed
lquot;else msg = quot;Cancel button was pushed