LoginSignup
0
0

JavaScript 乱数使ってカラーコード生成

Last updated at Posted at 2022-06-23

JavaScript で乱数 Math.random() 使ってカラーコード生成

// RGB
let rgbArray = [...Array(3)].map(i => Math.floor(Math.random() * 256));
let colorCode = 'rgb(' + rgbArray.join(',') + ')';

// Hex
let hex = '#' + Math.random().toString(16).slice(-6);
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0