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 is an enum

1 Answers  


Which operator is used to assign a value to a variable?

0 Answers  


How to count the number of element in an array using javascript?

0 Answers  


Why do we need hoisting in javascript?

0 Answers  


What is local and global scope?

0 Answers  






What does question mark mean in react?

0 Answers  


Explain what is javascript? List some data types supported by javascript?

0 Answers  


how to read and write a file using JavaScript?

0 Answers  


What does "1"+2+4 evaluate to?

10 Answers   Acheron, Satyam,


How to find the selected radio button immediately using the 'this' variable?

0 Answers  


Write JavaScript code to use file system in binary format?

0 Answers  


Can javascript code be broken in different lines?

0 Answers  


Categories