Javascript Code Snippets - Number
Random number between
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
// Example usage
const randomNumber = getRandomNumber(100, 500);
console.log(randomNumber);
Math.max
and Math.min
Get the highest or lowest value in an array using const numbers = [2, 1, 10, 5, 8, 3, 9];
const highestValue = Math.max(...numbers);
const lowest = Math.min(...numbers);