Hello!
My questions if about the best way to write the following stuff
most optimal with so few lines as posible? I provide an shorten
example, in my case it should be much longer (A-Z). I hope you see
what I trying to do.
Thanks!
- var Alfa = data.daily.[1].ico; // posible values A-Z
- var Beta = data.daily.[2].ico; // posible values A-Z
- var Gamma = data.daily.[3].ico; // posible values A-Z
-
- if (Alfa == 'A') {
- $('.testAlfa').attr('data-icon', 'A');
- }
- else if (Alfa == 'B') {
- $('.testAlfa').attr('data-icon', 'B');
- }
- else if (Alfa == 'C) {
- $('.testAlfa').attr('data-icon', 'C');
- }
- else{}
-
- if (Beta == 'A') {
- $('.testBeta').attr('data-icon', 'A');
- }
- else if (Beta == 'B') {
- $('.testBeta').attr('data-icon', 'B');
- }
- else if (Beta == 'C') {
- $('.testBeta').attr('data-icon', 'C');
- }
- else{}
-
- if (Gamma == 'A') {
- $('.testGamma').attr('data-icon', 'A');
- }
- else if (Gamma == 'B') {
- $('.testGamma').attr('data-icon', 'B');
- }
- else if (Gamma == 'C') {
- $('.testGamma').attr('data-icon', 'B');
- }
- else{}
-
-
- <span class="testAlfa" data-icon=""></span>
- <span class="testBeta" data-icon=""></span>
- <span class="testGamma" data-icon=""></span>