Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder MrEnder's Avatar
    Join Date
    Jul 2008
    Location
    Canada Ontario
    Posts
    258
    Thanks
    18
    Thanked 4 Times in 4 Posts

    Random Colors at Button Click

    I dont get why that doesn't work... it has me baffled 0.o

    Code:
    <html>
    <div id="divId">Button clicked 0 times</div>
    <input type="button" value="click me" onclick="divClick()" />
    <script type="text/javascript">
    
    var i = 0;
    
    function divClick() {
    
    var colorNum1 = Math.floor(Math.random()*255);
    var colorNum2 = Math.floor(Math.random()*255);
    var colorNum3 = Math.floor(Math.random()*255);
    var color = "rbg(" + colorNum1 + "," + colorNum2 + "," + colorNum3 + ")";
    
    
    i++;
    
    var divId = document.getElementById("divId");
    divId.style.backgroundColor = color;
    divId.innerHTML = "Button clicked " + i + " times";
    
    
    
    }
    
    </script>
    </html>
    figured it out finally i had rbg instead of rgb ><
    Last edited by MrEnder; 03-15-2010 at 06:46 AM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •