Can someone please help me with understanding what is wrong with my code here?
I keep getting an uncaught TypeError regarding my logoPath, but it is defined correctly. The page is www.eastvanbaseball.com/standings.
Uncaught TypeError: Cannot read properties of undefined (reading ‘logopath’)
This is a function that takes JSON data and computes standings. There is a bunch of additional logic after what I have shared, I can update with that if helpful, but I assume what i shared is where the issue lays. Thank you!
Below is my code:
<div class="selectGroupWrapper">
<div class="selectGroupList">
<select id="selectStandingsYear" onchange="getStandings()">
<option value="2023" selected>2023</option>
<option value="2022">2022</option>
<option value="2021">2021</option>
<option value="2019">2019</option>
<option value="2018">2018</option>
<option value="2017">2017</option>
</select>
</div>
</div>
<div id="standings_table"></div>
<div id="ringers_table"></div>
<script>
$(document).ready(function(){
$("select").trigger('change');
});
var teamDb = [
{ fullName: "Chinatown Cobras", lastName: "Cobras", abbr: "CHN", logoPath: "Cobras.png", participating: [true, true, true, false, true, true, true] },
{ fullName: "Clark Park Brawlers", lastName: "Brawlers", abbr: "CP", logoPath: "Brawlers-2019.png", participating: [true, true, true, false, false, true] },
{ fullName: "East Van Black Sox", lastName: "Black Sox", abbr: "SOX", logoPath: "Black_Sox.png", participating: [true, true, true, false, true, true, true] },
{ fullName: "Blood Alley Butchers", lastName: "Butchers", abbr: "BAB", logoPath: "butchers_2.png", participating: [false, false, false, false, false, false, false] },
{ fullName: "Gastown Gaolers", lastName: "Gaolers", abbr: "GAS", logoPath: "Gaolers.png", participating: [true, true, true, false, true, true, false] },
{ fullName: "Mt Pleasant Murder", lastName: "Murder", abbr: "MT", logoPath: "Murder.png", participating: [true, true, true, false, false, true, true] },
{ fullName: "Railtown Spikers", lastName: "Spikers", abbr: "RT", logoPath: "Spikers_alt.png", participating: [true, true, true, false, true, true, true] },
{ fullName: "Strathcona Stevedores", lastName: "Stevedores", abbr: "STR", logoPath: "Stevedores.png", participating: [true, true, true, false, false, true, true] },
{ fullName: "Sunrise Cosmos", lastName: "Cosmos", abbr: "COS", logoPath: "cosmos.png", participating: [true, true, true, false, true, true, true] },
{ fullName: "Sunset Stilettos", lastName: "Stilettos", abbr: "SET", logoPath: "Stilettos.png", participating: [true, true, true, false, false, true, true] },
{ fullName: "Vancouver Isotopes", lastName: "Isotopes", abbr: "VAN", logoPath: "isotopes.png", participating: [true, true, true, false, false, false, false] },
{ fullName: "Little Mountain Blasters", lastName: "Blasters", abbr: "LM", logoPath: "blasters.png", participating: [false, false, true, false, true, true, true] },
{ fullName: "Brewery Creek Mashers", lastName: "Mashers", abbr: "BC", logoPath: "mashers.png", participating: [false, false, false, false, true, true, true] },
{ fullName: "EVBL Ringers", lastName:"Ringers", abbr:"RNG", logoPath:"ev.png", participating: [false, false, false, false, false, true, false] }];
var yearToFilePath = {
"2023": "assets/schedule/evbl_schedule_2023.json",
"2022": "assets/schedule/evbl_schedule_2022.json",
"2021": "assets/schedule/evbl_schedule_2021.json",
"2019": "assets/schedule/evbl_schedule_2019.json",
"2018": "assets/schedule/evbl_schedule_2018.json",
"2017": "assets/schedule/evbl_schedule_2017.json"
};
var logoRootURL = "/assets/team_logos/";
var ringerNameData = {fullName:"EVBL Ringers",lastName:"Ringers",abbr:"RNG",logoPath:"ev.png"};
var tieCheck, numTies, c;
var useLogos = true;
var tableContent, ringerTableContent;
function getStandings() {
var visTeam, visAbbr, visLogo, visScore, homeTeam, homeAbbr, homeLogo, homeScore;
var teamNameData = [],
teamRecords = [],
teamSort = [],
obj,
getYear = document.getElementById("selectStandingsYear").value,
season = getYear - 2017,
teamSeasonIndex = 0;
for (let i = 0; i < teamDb.length; i++) {
console.log("Team Object:", teamDb[i]);
if (teamDb[i].participating[season]) {
obj = teamDb[i];
if (Array.isArray(teamDb[i].logoPath)) { // Check if logoPath is an array
console.log("Logo Path Array:", teamDb[i].logoPath);
for (let j = 0; j < teamDb[i].logoPath.length; j++) {
if (parseInt(teamDb[i].logoPath[j].yearStart) <= getYear) {
obj.logoPath = teamDb[i].logoPath[j].useLogo;
}
}
} else { // Handle the case where logoPath is not an array
obj.logoPath = teamDb[i].logoPath; // Assign logoPath directly
}
console.log("Modified Team Object:", obj);
obj.index = teamSeasonIndex;
teamNameData[teamDb[i].abbr] = obj;
teamSeasonIndex++;
obj = {
team: teamDb[i].abbr,
gp: 0,
w: 0,
l: 0,
t: 0,
rs: 0,
ra: 0,
strkW: 0,
strkL: 0,
strkUnb: 0,
strkWnl: 0,
lastFive: '',
lastW: 0,
lastL: 0,
lastT: 0,
rng_gp: 0,
rng_w: 0,
rng_l: 0,
rng_t: 0,
rng_rdiff: 0
};
teamRecords.push(obj);
obj = {
pct: 0,
p_pct: 0.5,
runDiff: 0,
rngwpct: 0.5,
totRunDiff: 0,
w_l: 0
};
teamSort.push(obj);
}
}