BraedenT24
BraedenT24

Reputation: 138

Can I change an ID used in a loop? Need to change 1 character in 6 iterations

I'm trying to use a loop (seen below) and want to change one character in an ID used throughout the loop. This would let me check all of the radio boxes in one loop without rewriting and adding the score up.

function scoreCalculationP1() {

    var score = 0;

    for (var i = 0; i <7; i++){
       if (scanP1("rb_correctP1[NEED characters a-f to change here in ID for iterations 1-6]") === true){
           score++;
        }
    }

    return score;
}

function scanP1(id){
    if (getChecked(id) === true){
        return true;
    }else {
        return false;
    }
}

Upvotes: 0

Views: 29

Answers (1)

Fabricator
Fabricator

Reputation: 12782

Use string concatenation:

scanP1("rb_correctP1["+i+"]")

Upvotes: 1

Related Questions