0

When I use this function to generate random colours the lint said:

Converts a string to an integer.

@param string — A string to convert into a number.

@param radix A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.

function colorGenerate() {
  const red = parseInt(Math.random() * 256);
  const green = parseInt(Math.random() * 256);
  const blue = parseInt(Math.random() * 256);
  return `rgb(${red}, ${green}, ${blue})`;
}
  • 1. I don't see rgba anywhere 2. rgba is not even relevant. Nor is rgb. 3. You're essentially asking how to generate a random *integer*. Because your current method is to generate a random floating point number then *parse it as an integer*. Use `Math.floor()` instead. See [Generating random whole numbers in JavaScript in a specific range?](https://stackoverflow.com/q/1527803) – VLAZ Feb 04 '22 at 14:23
  • Do not use `parseInt` with numeric types for input. Use `Math.floor` or similar instead. – Alnitak Feb 04 '22 at 15:29

0 Answers0