I need to create variable names in a loop (part of this seems to be working) and then get 26 of the 39 variables to perform simple math (for example: variable -= 10). Getting the variables recognized as variables, and not text, seems to be the issue.
This answer How do I create dynamic variable names inside a loop? suggested a possible solution, but I am not trying to use an array.
This works properly, it accesses 13 canvases named canvas1 through canvas13:
for (i = 1; i < 14; i++)
{
c = document.getElementById("canvas" + i.toString());
context = c.getContext("2d");
...
}
However, when I try to dynamically create canvas names, and dynamically create 2 variables in the same line, the variables are created as text.
for (i = 1; i < 14; i++)
{
document.getElementById('canvas' + i).style.filter = "brightness((bright" + i + " -= 10)%) contrast((cont" + i + " -= 10)%)";
}
Probably a dozen variations on this theme have failed. In a nutshell, the variables bright1 and cont1 through bright13 and cont13 are not recognized as variables that can be manipulated with math, they're recognized as text.
Right now I'm typing out 13 lines of code:
document.getElementById('canvas1').style.filter = "brightness(" + (bright1 -= 10) + "%) contrast(" + (cont1 -= 10) + "%)";
...
document.getElementById('canvas13').style.filter = "brightness(" + (bright13 -= 10) + "%) contrast(" + (cont13 -= 10) + "%)";
which is inefficient, to say the least.
So, what is the proper syntax to use so that bright1 through bright13 and cont1 through cont13 are variables instead of text?
Thank you!