Advanced AppLab Features

I am trying to iterate through a series of check-boxes to add up the total of them checked, resulting in the boolean value “true”.

However, variable scope barriers resist allowing any kind of foreach, for loop or iteration common in JavaScript. All of these elements require an individual id upon creation of each individual checkbox. They do not allow a “class” that I could apply to grab the tag for checkboxes as a group.

So, using the limitations inherent in the coding style of Code.org, how do I get the total of the checkboxes checked on the screen?

In terms of some efforts made already…The example listed in the code.org documentation for getChecked() only allowed me to grab the index of the number of the last checkbox selected. So if I selected the 11th checkbox, it would say 11, even I only selected 2 or 3 checkboxes. It was showing the location on the index, not the total checkboxes.

"
onEvent(“favorite”,“click”, function() {
var radioIDs = [“Red”,“Blue”,“Green”,“Orange”];
var index = 0;
while (index < radioIDs.length && !getChecked(radioIDs[index])) {
index++;
}
console.log("Your favorite color is: " + radioIDs[index]);
});

"

Source: https://studio.code.org/docs/applab/getChecked

Then after patterning another trial from another code.org resource, if one clicks on the Insert Event from the checkbox ID it will automatically insert something like this into the IDE.

"
onEvent(“IDname”, “change”, function() {
console.log (getChecked(“IDname”));
});

"

This would not work at all until I changed the wording to click, function. Now it works somewhat but outputs the wrong numbers and will not increment properly. It will for example, pop out a 1 after the first checkbox is checked, but then just stay there, even if there are 3 or 4 other boxes checked afterwards. It will only register the first one.

Any assistance or explanation of how to solve would be appreciated, since traditional JavaScript code will not work here.

Thanks,
Faith