Js Exercises | Java Script | Html

September 28, 2016 | Author: Anonymous | Category: HTML/HTML5, Java
Share Embed


Short Description

JavaScript exercises and solutions. 1. Write a JavaScript program to display the current day and time in the following f...

Description

 JavaScript exercises and solutions solutions

1.Wr i t eaJ av aSc r i ptpr ogr am t odi s pl ayt hec ur r entda yandt i mei nt hef ol l owi ngf or mat . Todayi s:Fr i day . Cur r entt i mei s:4PM :50:22 Samp mpl eSol ut i on:HTMLCode: view plai plain ncop copy y to clip boa board rd prin printt?

1. 2.



3.



4.

charset= ="utf-8"> ->6&&6>->6'''' 1(. c*%s*le.l*+t*&a', 1). t*&a' = mm6>F>6&&6>F>6'''' 18. c*%s*le.l*+t*&a', 1;. t*&a' = &&6>->6mm6>->6'''' 2. c*%s*le.l*+t*&a', 21. t*&a' = &&6>F>6mm6>F>6'''' 22. c*%s*le.l*+t*&a',

Ex pl a na t i on:

Dec l ar i ngaJ av aSc r i ptdat e   :I nJ av aSc r i ptDat eobj ec t sar ebas edonat i mev al uet hati s t henumberofmi l l i s ec ondss i nc e1Januar y ,1970UTC.Youc andec l ar eadat ei nt he f ol l owi ngwa ys: n ewDa t e ( ) ;

ne w Da t e( v a l ue ) ; ne w Dat e( dat eSt r i ng) ; newDat e( y ear ,mont h[ ,day [ ,hour [ ,mi nut es [ ,s ec onds [ ,mi l l i s ec onds ] ] ] ] ] ) ;

Theget Dat e( )   met hodi sus edt oge tt heda yoft hemont hf ort hes pec i fi eddat eac c or di ng t ol oc al t i me.Thev al uer et ur nedbyget Dat e( )i sani nt egerbet ween1and31. Thege t Mon t h ( )   met hodr et ur nst hemont hi nt hes pec i fi eddat eac c or di ngt ol oc al t i me,as az er obas edv al ue( wher ez er oi ndi c at est hefi r s tmont hoft hey ear ) .Thev al uer et ur ned b yget Mont h( )i sani nt egerbe t ween0and11.0c or r es pondst oJ anuar y ,1t oFebr uar y , andsoon. Theget Ful l Year ( )   met hodi sus edt ogett hey earoft hes pec i fi eddat eac c or di ngt ol oc al t i me.Thev al uer e t ur nedbyt heme t hodi sanabs ol ut enumber .Fordat esbe t weent he y ear s1000and9999,get Ful l Year ( )r et ur nsaf our di gi tnumber ,f orex ampl e,1985.

4.Rot at et hes t r i ng' w3r es our c e' i nr i ghtdi r ec t i onbyper i odi c al l yr emov i ngonel et t erf r om t heendoft hes t r i ngandat t ac hi ngi tt ot hef r ont . Sampl eSol ut i on:HTMLCode: view plaincopy to clip board print?

1. 2.



3.



4.

 aacr#$t as#c a%#mat#*%

5.

-------------------->, 2. for +var 'ear = 214 'ear -------------------->,

Ex pl a na t i on:

Dec l ar i ngaJ av aSc r i ptdat e   :I nJ av aSc r i ptDat eobj ec t sar ebas edonat i mev al uet hati s t henumberofmi l l i s ec ondss i nc e1Januar y ,1970UTC.Youc andec l ar eadat ei nt he f ol l owi ngwa ys: n ewDa t e ( ) ; ne w Da t e( v a l ue ) ; ne w Dat e( dat eSt r i ng) ; newDat e( y ear ,mont h[ ,day [ ,hour [ ,mi nut es [ ,s ec onds [ ,mi l l i s ec onds ] ] ] ] ] ) ;

Thege t Da y ( )   met hodi sus edt oge tt heda yoft heweekf ort hes pec i fi eddat eac c or di ngt o l oc al t i me,wher e0r epr es ent sSunda y .Thev al uer et ur nedbyget Da y( )i sani nt eger c or r es pondi ngt ot heda yoft heweek :0f orSunda y ,1f orMonda y ,2f orT ues da y ,ands o on.

6.Wr i t eaJ a v aSc r i p tp r ogr am wher et hepr o gr am t ak e sar an dom i nt eg erb et ween1t o1 0, t heus eri st henpr ompt edt oi nputagues snumber .I ft heus eri nputmat c heswi t hgues s

n umb er ,t h ep r o gr a m wi l l d i s p l a yame s s ag e" Goo dWo r k "o t h er wi s ed i s p l a yame s s ag e " No tma t c h e d" Sampl eSol ut i on:HTMLCode: view plaincopy to clip board print?

1. 2.   3.   4.   5.   Luess a %umer (.   ).   8.   ;.  

JavaScr i ptCode: view plaincopy to clip board print?

1. FF Let a ra%&*m #%teer fr*m 1 t* 1 #%clus#e 2.

var %um = ath.ce#l+ath.ra%&*m+, M 1,

3.

var %um = $r*m$t+>Luess the %umer etee% 1 a%& 1 #%clus#e>,

4.

if  +%um == %um,

5.   alert+>atche&>, (.

else

).   alert+>@*t matche&0 the %umer as > 6 %um,

Ex pl a na t i on:

TheMat h. c ei l ( )   f unc t i oni sus edt ogett hes mal l es ti nt egergr eat ert hanorequal t oagi v en number . TheMa t h . r a nd om( )   f unc t i oni sus edt ogetafl oat i ngpoi nt ,ps eudor andom numberi nt he r ange[ 0,1)t hati s ,f r om 0( i nc l us i v e)upt obutnoti nc l udi ng1( ex cl us i v e) ,whi c hy ouc an t hens cal et oy ourdes i r edr ange.

7.Wr i t eaJ av a Sc r i ptpr ogr am t oge tt hewebs i t eURL( l oadi ngpage) .

Sampl eSol ut i on:HTMLCode: view plaincopy to clip board print?

1. 2.   3.   4.   5.   r#te a aacr#$t $r*ram t* et the es#te N +l*a&#% $ae, (.   ).   8.   ;.  

JavaScr i ptCode: view plaincopy to clip board print?

1. FFr#te a aacr#$t $r*ram t* et the es#te N +l*a&#% $ae, 2. alert+&*cume%t.N,

Ex pl a na t i on:

do cume nt . URL:TheURLr eadonl ypr op er t yoft heDo c umenti nt er f ac er e t ur n st he doc umentl oc at i onasas t r i ng.

View more...

Comments

Copyright © 2017 DATENPDF Inc.