JSFiddle - React, Tailwind, and code Playground

JavaScript

var districts = [{
        bars: 0
    }, {
        bars: 2
    }, {
        bars: 2
    }, {
        bars: 3
    }, {
        bars: 0
    }, {
        bars: 3
    }]; //these are all the districts in the game + the amount of bars on them
    var PlayerControlledDistricts = [districts[0], districts[2], districts[3]]; //these are the 3 districts the player controlls
    var AmountOfBars = 0;
    for (i = 0; i < PlayerControlledDistricts.length; i++) {
        console.log(PlayerControlledDistricts[i]);
        AmountOfBars += parseInt(PlayerControlledDistricts[i].bars, 10);
    }
    alert(AmountOfBars);