Get a random number between 1 and 10 in JavaScript

Description

The following code shows how to get a random number between 1 and 10.

Example


<!--   w w w .  ja v a  2 s  .  c o m-->

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var num = Math.floor(Math.random() * 10 + 1);
document.writeln(num);

</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get a random number between 1 and 10 in JavaScript
Home »
  Javascript Tutorial »
    Development »
      Math
Javascript Tutorial Math
Calculate an exponent power in JavaScript
Calculate the absolute value of num in Java...
Calculate the arccosine of a number in Java...
Calculate the arctangent of the quotient of...
Calculate the cosine of a number in JavaScr...
Calculate the natural logarithm (base E) of...
Calculate the sine of a number in JavaScrip...
Calculate the square root of a number in Ja...
Calculates and returns the arcsine of a num...
Calculates the arctangent of a number in Ja...
Calculates the tangent of a number in JavaS...
Check if input value is a number from form ...
Convert Fahrenheit to Celsius back and fort...
Find out the max value in an array in JavaS...
Find out the min value in an array in JavaS...
Find out the value of PI in JavaScript
Find out the value of base 10 logarithm of ...
Find out the value of base 2 logarithm of e...
Find out the value of e, the base of the na...
Find out the value of natural logarithm of ...
Find out the value of natural logarithm of ...
Find out the value of square root of 2 in J...
Generate a random integer between 2 and 10 ...
Generate random URL in JavaScript
Get a random number between 1 and 10 in Jav...
Get a random number between values 0 and 1 ...
Get the max value in a list of parameter in...
Get the min value in a list of parameter in...
Math.round a random number in JavaScript
Round numbers down to the nearest integer v...
Round numbers up to the nearest integer val...
Round the number with Math.round() in JavaS...
Round to get the largest integer number equ...
Round to get the smallest integer greater t...
Select a random item from an array in JavaS...
Use Math.PI to do calculation in JavaScript
Use Recursive function to calculate Fibs in...