Skip to main content
InterviewHubPRO
Section Overview
Q155

Question 155 of 536

Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

29%
JavaScript & V8 Internals (536 Qs)•Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

Can you write a random integers function to print integers within a range

mid LevelCode ExampleHTTP & REST APIs

Yes, you can create a proper random function to return a random number between min and max (both included)

javascript
  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