JavascriptSyntax

JavascriptSyntax - x ="big&quot alert...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Basic Javascript constructs Control structures if ( Boolean condition ) { more statements } if (condition) { … } else { … } for ( k = 1 ; k < 10 ; k++ ) { more statements } Arrays var A = [ 'aaa' , 'bbb' , 'ccc' ] A[k] accesses element k ( A[0], etc ) onclick = "f( )" -- triggers f when tag is clicked function f ( ) { --- } -- to define f Other events: onmouseover, onmouseout, onfocus, onblur, etc. Built-in Functions Math.random ( ) -- returns random decimal between 0 and 1 [0, 1) Math.floor ( x ) -- returns whole number part of x, like 3.7 becomes 3 parseInt ( x ) converts a string of digits x to an integer
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x = &amp;quot;big&amp;quot; alert ( x + &amp;quot;dog&amp;quot;) pops up &amp;quot;bigdog&amp;quot; String Manipulation k = 2 y = &amp;quot;number k&amp;quot; --- is number k y = &amp;quot;number &amp;quot; + k --- is number 2 DOM functions document.getElementById(id) is used in tandem with an element with given id, containers like &amp;lt;div id=1&amp;gt; &amp;lt;/div&amp;gt; are useful document.getElementById( some id).value -- returns value of element with given id document.getElementById( some id).innerHTML -- returns HTML inside element document.getElementById( some id).style.backgroundColor -- returns background color of element with given id...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online