2. random()
The Random Method returns number between 0 (inclusive) and 1 (exclusive).
Math.random();
There are no parameters for the method random().
3. Shifting and Scaling
The range of values produced directly by a random is often different than what is needed
in a specific application.
Eg:
Dice
Coin Tosing
4. Scaling and Shifiting
Math.floor( 1 + Math.random() * 6 )
Here, Math.random is multiplied with 6, so that we get a range from 0.0 to 6.0
This is called scaling.
Adding 1(here) to the obtained value is called shifting.
Math.floor() is used to determine the closest integer not greater than the argument value
Eg: Math.floor(6.75) is 6 and Math.floor(1.89) is 1
(Program 1)
5. Displaying Random Images
Web content that varies randomly can add dynamic, interesting effects to a page.
Alert()
Prompt()
Scripts are often used to respond to user initiated events.
Has Limited Features In receiving input from the
user
6. Events
Click Event
Occurs when the user clicks on the button.
This style of Programming is known as event-driven programming
8. Event Handler
The Function that’s called when an event occurs is known as the event
handler.
When a GUI event occurs in a form, the browser calls the specified event-
handling function.
Before any event can be processed, each element must know which event-
handling function will be called when a particular event occurs.