How to color table cells with random color using random number generator Math.random ()?

  • Indicate the language tag in question - gil9red

2 answers 2

var r = Math.floor(Math.random()*256); var g = Math.floor(Math.random()*256); var b = Math.floor(Math.random()*256); document.body.bgColor = 'RGB(' + r + ',' + g + ',' + b + ')'; 

    Like that:

     var hex = '#'+Math.floor(Math.random()*16777215).toString(16); console.log(hex); // #f69608