Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8797565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:52:53+00:00 2026-06-13T23:52:53+00:00

Hi I was playing around with math random the other day and made an

  • 0

Hi I was playing around with math random the other day and made an RGB color generator and successfully was able to use a text input to limit the roof of the random number, but was unable to get the floor working. Here is the JSFiddle
http://jsfiddle.net/synthet1c/3KR83/

and here is the Javascript function I made

function randomColor(){

    var roof =  document.getElementById('textRoof').value,
        floor = document.getElementById('textFloor').value;

    var r = Math.floor((Math.random()*roof)+floor);
    var g = Math.floor((Math.random()*roof)+floor);
    var b = Math.floor((Math.random()*roof)+floor);


    if (r < 10) { var r = "0" + r}
    if (r < 100) { var r = "0" + r};

    if (g < 10) { var g = "0" + g};
    if (g < 100) { var g = "0" + g};

    if (b < 10) { var b = "0" + b};
    if (b < 100) { var b = "0" + b};

    document.getElementById('header').style.color= "rgb("+r+","+g+","+b+")"
    document.getElementById('text').value = "rgb("+r+","+g+","+b+")"

}

This is just for the sake of learning it, but any help is appreciated.

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:52:54+00:00Added an answer on June 13, 2026 at 11:52 pm
    var roof =  document.getElementById('textRoof').value,
      floor = document.getElementById('textFloor').value;
    
    // convert the string values to integer values
    roof = parseInt(roof);
    floor = parseInt(floor);
    
    var r = Math.floor((Math.random()*(roof-floor))+floor);
    var g = Math.floor((Math.random()*(roof-floor))+floor);
    var b = Math.floor((Math.random()*(roof-floor))+floor);
    

    live example

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been playing around with Python and math lately, and I ran in
Playing around with Python - tkInter - Entry widget - when I use validatecommand
been playing around with ResolveClientUrl(~/Confirmation.aspx) and other methods.. I am tryin go get the
I'm playing around with code like this: <s:Button id=test label=test transformX={Math.floor(test.width/2)} rotationY=20 x=20 y=20
Possible Duplicate: Is JavaScript's Math broken? I have just started playing around with Javascript
Playing around with generating text randomly with each page refresh using php. Is there
Im playing around with the new geometry library made available in boost 1.47 and
I've been playing around with some math recently and I would like to know
Playing around with Lucene. Trying to make my changes visible for other reading threads.
Playing around with MongoDB and NoRM in .NET. Thing that confused me - there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.