Answers for "javascipt random color"

27

js random hex color

'#'+Math.floor(Math.random()*16777215).toString(16);
Posted by: Guest on February-25-2020
0

js random color

//1.
var color = '#'+Math.floor(Math.random()*256).toString(10);
//2.
var color = '#'+Math.floor(Math.random()*0xffffff).toString(16);
//3.
function rgb(){// rgb color random
		var r = Math.floor(Math.random()*256);
		var g = Math.floor(Math.random()*256);
		var b = Math.floor(Math.random()*256);
		var rgb = 'rgb('+r+','+g+','+b+')';
		return rgb;
	}
//4.
function color16(){// hexadecimal color random
  var r = Math.floor(Math.random()*256);
  var g = Math.floor(Math.random()*256);
  var b = Math.floor(Math.random()*256);
  var color = '#'+r.toString(16)+g.toString(16)+b.toString(16);
  return color;
}
Posted by: Guest on June-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language