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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Which type of variable among global and local, takes precedence over other if names are same?

501


How do you create array in javascript?

525


How does javascript work?

495


What do “1”+2+4 evaluate to?

533


What is an Event Bubbling in Javascript?

570






Why are callbacks used?

477


What is prototype in javascript and how do you use it?

447


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

445


How to get height and width of different browser in Javascript?

524


How to encode and decode a url in javascript?

538


What is the difference between registerclientscriptblock and registerstartupscript?

505


Why is javascript used for web pages?

443


Which is best for front end?

480


How do browsers work?

511


What is the use of anonymous function in javascript?

466