0% found this document useful (0 votes)
115 views20 pages

Javascript Book

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 20

Introduction to JavaScript

W3Schools
www.w3schools.com


apc1424@yahoo.com

* W3Schools



........................................................ ....................................................... . ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ...................... .................................. ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................ ........................................................

! Java HTML : ... return If Ifelse Switch


. Netscape . Navigator Internet Explorer .

!
: WWW HTML . . www.w3schools .com


.HTML . . - .HTML . . .

Java
! ... ) ( C ++. C


HTML HTML ! HTML . HTML )">1 document.write("<h1>"+name+"</h .HTML .HTML HTML .HTML - .Servers


! )( HTML ... FrontPage HTML ... Note Pad file.htm file.html IE .Navigator

IE

HTML
:
><html ><body >"<script type="text/javascript )"!document.write("Hello World ></script ></body ></html : HTML

ex1.html :
!Hello World

: HTML > <script :


>"<script type="text/javascript

: document.write
)"!document.write("Hello World

><script
></script


++ C )( " ; ".. ! .


. - HTML HTML :
>"<script type="text/javascript -!<some statements >--// ></script

)//( . : // ) --!<// ( .

: ...
body ... ) (. head ... :HEAD functions head . . :BODY .body : .External File


. . : head head .
><html ><head >"<script type="text/javascript some statements ></script ></head

:body ) ( .
><html ><head ></head ><body >"<script type="text/javascript some statements ></script ></body

head :body head .body


><html ><head >"<script type="text/javascript some statements ></script ></head ><body >"<script type="text/javascript some statements ></script ></body

. . ) .js: (file.js :
)"document.write("This script is external

. example.js : >.<script " "scr :HTML


><html ><head ></head ><body ><script src="example.js"></script ></body ></html


"" . ) ( . . : case sensitive Book book bOoK... _ . underscore : var
var strname = some value

:var
strname = some value

:
"var strname = "Ahmed

:
"strname = "Ahmed

. ) = ( strname .Ahmed . .Local Variables . . Global Variables .


. :

4 3 02 3 5.2 1 2 0 6=x 4=x

2=x 2+x 2=x 5-x 4=x 5*x 5/51 2/5 2%5 8%01 2%01 5=x ++x 5=x --x

+ * / % ++ --

... ...

x=y x+=y x-=y x*=y x/=y x%=y


...
x=y x=x+y x=x-y x=x*y x=x/y x=x%y

= =+ =- =* =/ =%

8==5 )( 8=!5 )( 8>5 )( 8<5 )( 8=>5 )( 8=<5 )(

== =! > < => =<

6=x 3=y )1 > (x < 10 && y )( 6=x 3=y )5== (x==5 || y )( 6=x 3=y ) !(x==y )( ) not( ! ) or( ||

) and(

&&

: "!. "Hello World + .


"txt1="What a very "!txt2="nice day 2txt3=txt1+txt

3 txt "!." What a verynice day .


"txt1="What a very "!txt2="nice day 2txt3=txt1+" "+txt " txt1="What a very "!txt2="nice day 2txt3=txt1+txt

3 txt "!." What a very nice day


) ( event . : ) head( . :
)"alert("This is a message

argument .
)function myfunction(argument1,argument2,etc { some statements }

:
)(function myfunction { some statements }

. . head . :
)function result(a,b { c=a+b return c }

. :
)myfunction(argument1,argument2,etc

:
)(myfunction

return . return . : :
)function total(a,b { result=a+b return result }

) ( :
)3,2(sum=total

5 . . sum


) ( . : if ) .(true ifelse . switch . If Ifelse if - ) (false .
)if (condition { code to be executed if condition is true } ) : (Good Morning >"<script type="text/javascript ,01 //If the time on your browser is less than .//you will get a "Good morning" greeting )(var d=new Date )(var time=d.getHours )01<if (time { )">document.write("<b>Good morning</b } ></script

else ) ( ) (. . Ifelse

Ifelse
if (condition) { code to be executed if condition is true } else { code to be executed if condition is false } Good Morning ! ) : ( Good day! <script type="text/javascript"> //If the time on your browser is less than 10, //you will get a "Good morning" greeting. //Otherwise you will get a "Good day" greeting. var d = new Date() var time = d.getHours() if (time < 10) { document.write("Good morning!") } else { document.write("Good day!") } </script>

Switch .
switch (expression) { case label1: code to be executed if expression = label1 break case label2: code to be executed if expression = label2 break default: code to be executed if expression is different from both label1 and label2 }

) ( expression - ) ( case default . . break ( : ) :


<script type="text/javascript"> //You will receive a different greeting based //on what day it is. Note that Sunday=0, //Monday=1, Tuesday=2, etc. var d=new Date() theDay=d.getDay() switch (theDay) { case 5: document.write("Finally Friday") break case 6: document.write("Super Saturday") break case 0: document.write("Sleepy Sunday") break default: document.write("I'm looking forward to this weekend!") } </script>


.
2variablename=(condition)?value1:value


" greeting=(visitor=="PRES")?"Dear President ":"Dear

: visitor PRES " "Dear President greeting visitor PRES " "Dear .greeting


. : while . dowhile . for . while ) ( :
)while (condition { code to be executed }

dowhile .
do { code to be executed } )while (condition

for .
)for (initialization; condition; increment { code to be executed }


Date Object Math Object .Array Object Date Object ) (. " "new . : my_date
)(var my_date=new Date

methods .my_date :
)(my_date.getDate

:
new new new new new )"Date("Month dd, yyyy hh:mm:ss )"Date("Month dd, yyyy )Date(yy,mm,dd,hh,mm,ss )Date(yy,mm,dd )Date(milliseconds

:
var var var var var my_date=new my_date=new my_date=new my_date=new my_date=new )"00:41:31 8891 ,21 Date("October )"8891 ,21 Date("October )00,41,31,21,90,88(Date )21,90,88(Date )005(Date

Math Object . . )( )( - " "r_number :


)(r_number=Math.random

": "r_number
)6.8(r_number=Math.round

: E ) abs(x .x

:
myfunction myFunction . )( )} ] " ' ' " [ { ( . . :
"name="Hege "name = "Hege

\ . :
\ document.write("Hello )"!World

: :
\ document.write )"!("Hello World

-. ) & ; ' "( \ :


)"."\document.write ("You \& I sing \"Happy Eid

:
."You & I sing "Happy Eid

// :
sum=a + b //calculating the sum

" */ " " /* " :


sum=a + b /*/*calculating the sum

:
/* This is a comment block. It contains /*several lines

: ><script Script Block ></script Variable true/false . Initialize . Call Function . . Argument Expression . . Statement . Statement Block For For Loop . While While Loop . Conditional . Branching Multi-way Branching default Return .
JavaScript in easy steps .

:
) ( ) ( "" .Code ) ( ) ( ) - ( ... Loops . )( )( " ". ) ( apc1424@yahoo .com .W3Schools

apc1424@yahoo.com W3Schools

You might also like