Random Color

by Lazaro Contreras

HTML

<button id="1">Click Me!</button>

<button id="2">Click Me!</button>

CSS

button{
  border:none;
  display:block;
}

JavaScript

window.onload = ini();
function ini(){
 var b1= document.getElementById('1');
 var b2= document.getElementById('2');
 b1.addEventListener('click',RandomColor1,false);
 b2.addEventListener('click',RandomColor2,false);
}
function RandomColor1() {
    var letters = '0123456789ABCDEF';
    var color = '#';
    for (var i = 0; i < 6; i++ ) {
    color += letters[Math.floor(Math.random() * 16)];
    document.getElementById('1').style.backgroundColor = color;
    document.getElementById('1').innerHTML = color;
    }
}
function RandomColor2() {
    var r = Math.floor(Math.random() * 256);
    var g = Math.floor(Math.random() * 256);
    var b = Math.floor(Math.random() * 256);
    color2 = "rgb("+r+", "+g+", "+b+")";
    document.getElementById('2').style.backgroundColor = color2;
    document.getElementById('2').innerHTML = color2;
}