- Joined
- Dec 5, 2012
- Messages
- 1
- Reaction score
- 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();
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();