116Part IIJavaScript Tutorialwhere nequals the top number (Windows 2003 server web) of

116Part IIJavaScript Tutorialwhere nequals the top number of the range. For the dice game, the formula for each die isnewDieValue = Math.floor(Math.random() * 6) + 1; To see this, enter the right-hand part of the preceding statement in the top text box of TheEvaluator Jr. and repeatedly click the Evaluate button. One bit of help JavaScript doesn t offer except in IE5.5+ and Mozilla-based browsers is a wayto specify a number-formatting scheme. Floating-point math can display more than a dozennumbers to the right of the decimal. Moreover, results can be influenced by each operatingsystem s platform-specific floating-point errors, especially in earlier versions of scriptablebrowsers. For other browsers you must perform any number formatting for dollars andcents, for example through your own scripts. Chapter 28 provides an example. The Date ObjectWorking with dates beyond simple tasks can be difficult business in JavaScript. A lot of thedifficulty comes with the fact that dates and times are calculated internally according toGreenwich Mean Time (GMT) provided the visitor s own internal PC clock and control panelare set accurately. As a result of this complexity, better left for Chapter 29, this section of thetutorial touches on only the basics of the JavaScript Dateobject. A scriptable browser contains one global Dateobject (in truth, one Dateobject per window) that is always present, ready to be called upon at any moment. The Dateobject is anotherone of those static objects. When you wish to work with a date, such as displaying today sdate, you need to invoke the Dateobject constructor function to obtain an instance of a Dateobject tied to a specific time and date. For example, when you invoke the constructor withoutany parameters, as invar today = new Date(); the Dateobject takes a snapshot of the PC s internal clock and returns a date object for thatinstant. Notice the distinction between the static Dateobject and a Dateobject instance, which contains an actual date value. The variable, today, contains not a ticking clock, but avalue that you can examine, tear apart, and reassemble as needed for your script. Internally, the value of a Dateobject instance is the time, in milliseconds, from zero o clockon January 1, 1970, in the Greenwich Mean Time zone the world standard reference pointfor all time conversions. That s how a Dateobject contains both date and time information. You can also grab a snapshot of the Dateobject for a particular date and time in the past orfuture by specifying that information as parameters to the Dateobject constructor function: var someDate = new Date( Month dd, yyyy hh:mm:ss ); var someDate = new Date( Month dd, yyyy ); var someDate = new Date(yy,mm,dd,hh,mm,ss); var someDate = new Date(yy,mm,dd); var someDate = new Date(GMT milliseconds from 1/1/1970); If you attempt to view the contents of a raw Dateobject, JavaScript converts the value to thelocal time zone string as indicated by your PC s control panel setting. To see this in action, use The Evaluator Jr. s top text box to enter the following: new Date(); Your PC s clock supplies the current date and time as the clock calculates them (eventhoughJavaScript still stores the date object s millisecond count in the GMT zone). You can,
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision web design programs services

Leave a Reply