Can you write a random integers function to print integers with in a range?



Can you write a random integers function to print integers with in a range?..

Answer / hrpatelsoft@gmail.com

function randomInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
randomInteger(1, 100); // returns a random integer from 1 to 100
randomInteger(1, 1000); // returns a random integer from 1 to 1000

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More JavaScript Interview Questions

What are the three core languages in web pages?

0 Answers  


Which is better python or javascript?

0 Answers  


Is there any class in javascript?

0 Answers  


What is === in javascript?

0 Answers  


How to write a function in javascript?

0 Answers  


How do I open javascript on my iphone?

0 Answers  


What is the difference between the operators '==' and '==='?

0 Answers  


What are the methods of validating whether the form is secure?

1 Answers  


What are the predefined functions in javascript?

0 Answers  


How we can get the value of an element using javascript?

0 Answers  


Name the datatypes of javascript?

0 Answers  


What do mean by NULL in Javascript?

0 Answers  


Categories