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

Is a function an object?

0 Answers  


What is null variable?

0 Answers  


Explain prototypal/differential inheritance?

0 Answers  


What is a prompt box in javascript?

0 Answers  


Create an array in javascript with a list of 4 colors, assign that array to the variable, ‘colors’.

0 Answers  






What are the ways to define a variable in javascript?

0 Answers  


How would you compare two objects in JavaScript?

0 Answers  


What are all the looping structures in javascript?

0 Answers  


What is "this"?

0 Answers  


What are the types used in javascript?

0 Answers  


What are exports & imports?

0 Answers  


What is rest parameters in javascript?

0 Answers  


Categories