Last Updated : Jan 1, 2023
Math.random() function is only used to generate a random number between 0 and 1. So, we have to modify this method to print number between 0 and 3 which we need.
- First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
- Secondly, the <html> tag is used to indicate the beginning of an HTML document.
- As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
- Here, first now body started and body is a paired tag. All the data which we want to show on browser screen is written here.
- Now, here inside body we create a heading, a button and a paragraph. We create a function on paragraph which work with click on button.
- Now, inside script we create a function with name getInteger and inside this function we pass two parameters that is min and max. Now, let us go inside function.
- Inside function we return the value of integer with help of math.random() and math.floor() function. You can see the code for reference.
- Now, when we click the button. Inside button we use onclick method. With click on button. The value of the demo gets changed and is get from getInteger() function.
- Inside this function we also pass two parameter that is 0 and 4. Where 0 is the minimum value and 4 is maximum value. It helps us to print a number between 0 and 3 because 4 is excluded.
- At last, the <body> and <html> tags are closed with </body> and </html> respectively.
At last in conclusion, here we want to say that with the help of this article we are able to print or generate a number between 0 and 3.