Javascript Link Displays Dice Roll in Console

Javascript Link Displays Dice Roll in Console

 
This example shows the standard expression to generate a random number from 1 to 6. It uses thje Math class methods floor and random. The floor method truncates decimals, rounding a number down making it an integer, a number without decimals.

Testing to See If It Works

You need a web browser console window open that supports the console object for this example. In that console window when you load or refresh the page you will see the messages showDieRoll() and a number from 1 to 6 such as 4.

lh-inline-image-link fid=”js-call-function-die-roll-console” aria-label=”Example of why you see.” title=”Example of why you see.” alt=”Example of why you see.” height=”290″ width=”290″/>

If your console window was not enabled when you opened this page, then enable and refresh/reload this page to see again.

Get Javascript Website Skills in 2 Weeks

Javascript website skills needed for interactivity: menus, buttons and forms.