A Simple Question?

Discussion in 'Javascript' started by Paksennarion, Dec 5, 2012.

  1. Paksennarion

    Paksennarion

    Joined:
    Dec 5, 2012
    Messages:
    1
    Likes Received:
    0
    Hello.

    I'm trying to make a function that will take a range and associate a rgb color with each increment in that range, applying a lighter shade or darker shade depending on how high or low the number in question is. However my code isn't working, and I was wondering if it was because of the way my function is set up. Can you reference a variable from a previous function in a new function, or do you have to call the function inside of the second function?

    Here's my problem:

    var a = [
    {X: 12},
    {X: 15},
    {X: 13},
    {X: 19},
    {X: 11},
    {X: 10}

    ];

    var max = 19; //this will be done with 2 underscore functions later

    var min = 10;

    function convert(){
    var i = (Math.round(255*a("X")/max));
    return i;
    }


    function drawThings(){
    for(var i=0; i< a.length; i++){
    var tag = $("<div>a</div>");
    tag.css("background" + "(" + "function convert();" + ", " + "function convert();" +" , "+ "function convert();" + ")");
    $("body").append(tag);
    }
    }

    drawThings();
    ‚Äč
     
    Paksennarion, Dec 5, 2012
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave E
    Replies:
    7
    Views:
    958
    Josh Twist
    Jan 11, 2006
  2. Daniel Frey

    Simple Question - Simple Answer?

    Daniel Frey, Dec 28, 2004, in forum: XML
    Replies:
    4
    Views:
    1,132
    Daniel Frey
    Jan 12, 2005
  3. jmac@berkeley.edu

    A few simple problems in a simple program.

    jmac@berkeley.edu, Jul 22, 2003, in forum: C Programming
    Replies:
    7
    Views:
    921
    Stig Brautaset
    Jul 23, 2003
  4. Eric
    Replies:
    2
    Views:
    557
    kbutterly
    Dec 7, 2006
  5. Oli

    simple simple question

    Oli, Jan 26, 2004, in forum: ASP General
    Replies:
    10
    Views:
    627
    Roland Hall
    Jan 26, 2004
  6. Peter Bailey

    simple, simple array question

    Peter Bailey, Apr 8, 2008, in forum: Ruby
    Replies:
    7
    Views:
    496
    Peter Bailey
    Apr 8, 2008
  7. Kirk

    Simple Question = simple answer?

    Kirk, Sep 23, 2003, in forum: Javascript
    Replies:
    1
    Views:
    285
    Martin Honnen
    Sep 23, 2003
  8. db
    Replies:
    7
    Views:
    457
Loading...