# Trying to assign values to a grid based on lowest value assigned

Here is my issue.  I have a grid type question and the headings are
1. 0%-(do not do this)
2. (1% to 19%)
3. (20% to 39%)
4. (40% to 59%)
5. (60% to 79%)
6. (80% or more)

There are 7 items in the rows...

This is a select type grid.  The respondent is to check each row with one of the above percents - however - they cannot go over 100%... I need to count each response with the lowest value - so for instance if someone selects the 20%-39% choice, that would be counted as a 20%, a 1%-19% would be 1%, and so on.  Then when they are done, I need to sum all responses up and make sure their total does not equal 100% or more...

I know that it can be done in a constant sum, but I need to figure it this way.  This is my logic so far, but it's not working... I hope this isn't too confusing. Thanks.

var counter = 0;

if (SSI_GetValue("S1_r1") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r2") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r3") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r4") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r5") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r6") = 1){counter = counter + 0;}
if (SSI_GetValue("S1_r7") = 1){counter = counter + 0;}

if (SSI_GetValue("S1_r1") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r2") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r3") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r4") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r5") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r6") = 2){counter = counter + 1;}
if (SSI_GetValue("S1_r7") = 2){counter = counter + 1;}

if (SSI_GetValue("S1_r1") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r2") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r3") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r4") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r5") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r6") = 3){counter = counter + 20;}
if (SSI_GetValue("S1_r7") = 3){counter = counter + 20;}

if (SSI_GetValue("S1_r1") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r2") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r3") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r4") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r5") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r6") = 4){counter = counter + 40;}
if (SSI_GetValue("S1_r7") = 4){counter = counter + 40;}

if (SSI_GetValue("S1_r1") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r2") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r3") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r4") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r5") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r6") = 5){counter = counter + 60;}
if (SSI_GetValue("S1_r7") = 5){counter = counter + 60;}

if (SSI_GetValue("S1_r1") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r2") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r3") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r4") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r5") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r6") = 6){counter = counter + 80;}
if (SSI_GetValue("S1_r7") = 6){counter = counter + 80;}

if (counter > 100) {strErrorMessage = "Your percentage used is more than 100%, please review your answers.";}

We are using 7.0.30
asked Jun 27, 2017
Brian has it exactly right.  As an optional change, you can shorten up some of this code using looping.  Here is the last block of your code in a for loop:

```for (var r = 1; r <= 7; r++) {
if (SSI_GetValue('S1_r' + r) == 6) {
counter += 80;
}
}
```

If you really want to cut it down, you can create what is known as a dictionary to convert SSI_GetValue's output into how much the counter needs to be incremented.  Here's all six of your blocks done with a dictionary and a loop:

```var increments = {
1: 0,
2: 1,
3: 20,
4: 40,
5: 60,
6: 80
};
for (var r = 1; r <= 7; r++) {
counter += increments[SSI_GetValue('S1_r' + r)];
}
```