Looking to achieve something like this:
number = "first";
number2 = "second";
var firstColor = "red";
var secondColor = "blue";
//Changes background to red:
div.style.backgroundColor = number+"Color";
//Changes background to blue:
div.style.backgroundColor = number2+"Color";
When I try this it doesn't not work for me and the styles are not applied. How can I do this dynamically.
Edit:
I have a series of else ifs to pick font text depending on which team is selected. I want to create the variables like this:
liverpoolColor = "red";
else if(team == "liverpool"){
for (var x = 0; x < areas.length; x++){
//Then change the color dynamically like this:
areas[x].style.color = team+"Color";
}
}
That way I can remove the else ifs completely and clean up my code: