{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

20 function calculation IV - /As k fo r a ll IDs a n d/s e...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
<bo dy > <h2>Rando m  S tude nt  Pic ke r</h2>  <script type="text/javascript"> //The global array of student IDs var all = new Array(5); setupIDs (); writeIDsToDocument (); </script> <a href="javascript:  pickOne ();"> Pic k a s tude nt</a> : <s pan id="re s ult"></s pan> </bo dy> //As k fo r all IDs  and //s e t the  c o nte nt in the  array func tio n  setupIDs () { var i=0; while  (i<5) { all[i]=pro m pt("Input a s tude nt ID"); i++; } } //Write  all IDs  to  the  do c um e nt func tio n  writeIDsToDocument () { var i=0; while  (i<5) { do c um e nt.write (all[i]); do c um e nt.write ('<br/>'); i++; } } //S e le c t a rando m  s tude nt ID fro m  the  array func tio n  pickOne () { var idx=Math.flo o r(Math.rando m ()*5); do c um e nt.g e tEle m e ntById("re s ult").inne rHTML=all[idx]; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Strings More about String Manipulations Each string may contain 0 or more characters. The .length property tells the number of characters in the string. Examples: Each character in a string has an index . The first character is located at index 0. To get the character at a given location: The charAt( index) method: Returns the character at the given index .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}