Change the object states of several objects with Javascript

Hello,

I use the following script to change the object states of several objects (Alphabet):

var L = prez.variable(‘letter’);

switch (L) {
case ‘A’:
prez.object(‘a1’).state(‘j’);
prez.object(‘a2’).state(‘j’);
prez.object(‘a3’).state(‘j’);
prez.object(‘a4’).state(‘j’);
prez.object(‘a5’).state(‘j’);
prez.object(‘a6’).state(‘j’);
prez.object(‘a7’).state(‘j’);
prez.object(‘a8’).state(‘j’);
prez.object(‘a9’).state(‘j’);
prez.object(‘a10’).state(‘j’);
break;
case ‘B’:
prez.object(‘b1’).state(‘j’);
prez.object(‘b2’).state(‘j’);
prez.object(‘b3’).state(‘j’);
prez.object(‘b4’).state(‘j’);
prez.object(‘b5’).state(‘j’);
prez.object(‘b6’).state(‘j’);
prez.object(‘b7’).state(‘j’);
prez.object(‘b8’).state(‘j’);
prez.object(‘b9’).state(‘j’);
prez.object(‘b10’).state(‘j’);
break;
default:
alert (‘No value found’);
}

Is there a way to change the object states more efficiently within the code?
Because, if I use that for 26 cases the code gets quite long.
Sorry, I am only a newbie to javascript.

Regards,
Augustin

ActivePresenter version: 8.3.2

OS: Win 10

Hi Augustin,

You can use the following script:

var L = prez.variable('letter').toLowerCase();
for (var i = 1; i <= 10; ++i)  {
  var obj = prez.object(L + i);
  if (obj)
    obj.state('j');
}

Regards