-
-
Save cferdinandi/27eb9fa074cbc40b049db50714ed71c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Random Number</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
</head> | |
<body> | |
<script> | |
/** | |
* Get a random integer with a minimum and maximum value | |
* (c) Chris Ferdinandi, MIT License, https://gomakethings.com | |
* @param {Integer} min The minimum value | |
* @param {Integer} max The maximum value | |
* @return {Integer} A random number | |
*/ | |
function randomNumber (min = 0, max = 1000) { | |
return Math.floor(Math.random() * (max - min + 1) + min); | |
} | |
// Get a random number between 5 and 42 | |
let rand = randomNumber(5, 42); | |
console.log(rand); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment