javascript - JS Loop not looping until I comment out my switch method -
been stuck on problem few hours loop won't loop (only 1 iteration).
the following code:
function getscore(summonerid) { $.ajax({ datatype: "json", type: 'get', url: 'https://na.api.pvp.net/api/lol/na/v2.2/matchhistory/' + summonerid + '/?queuetype=normal_5x5_blind,normal_5x5_draft,ranked_solo_5x5,ranked_premade_5x5,normal_5x5_draft,ranked_team_5x5&beginindex=0&endindex=9&api_key=***', success: function (data, state) { (i = 0; < 10; i++){ // loop won't work. console.log(i); console.log(state); //v1.1.0 if (data.matches[i].participants[0].stats.firstbloodkill == true){ firstbloodarray[i] = 1; }else{ firstbloodarray[i] = 0; } if (data.matches[i].participants[0].stats.firsttowerkill == true){ firsttowerarray[i] = 1; }else{ firsttowerarray[i] = 0; } if (data.matches[i].participants[0].stats.firsttowerkill == true){ firstinhibitorarray[i] = 1; }else{ firstinhibitorarray[i] = 0; } damagedealtarray[i] = data.matches[i].participants[0].stats.totaldamagedealt; healingdealtarray[i] = data.matches[i].participants[0].stats.totalheal; damagetakenarray[i] = data.matches[i].participants[0].stats.totaldamagetaken; inhibitorarray[i] = data.matches[i].participants[0].stats.inhibitorkills; towerarray[i] = data.matches[i].participants[0].stats.towerkills; //timeline arrays tl_arr_cspm_zero_ten[i] = data.matches[i].participants[0].timeline.creepspermindeltas.zerototen; tl_arr_cspm_ten_twenty[i] = data.matches[i].participants[0].timeline.creepspermindeltas.tentotwenty; if(data.matches[i].participants[0].timeline.creepspermindeltas.twentytothirty != undefined) { tl_arr_cspm_twenty_thirty[i] = data.matches[i].participants[0].timeline.creepspermindeltas.twentytothirty; }else{ tl_arr_cspm_twenty_thirty[i] = 0 } if(data.matches[i].participants[0].timeline.creepspermindeltas.thirtytoend != undefined) { tl_arr_cspm_thirty_end[i] = data.matches[i].participants[0].timeline.creepspermindeltas.thirtytoend; }else{ tl_arr_cspm_thirty_end[i] = 0 } tl_arr_xppm_zero_ten[i] = data.matches[i].participants[0].timeline.xppermindeltas.zerototen; tl_arr_xppm_ten_twenty[i] = data.matches[i].participants[0].timeline.xppermindeltas.tentotwenty; if(data.matches[i].participants[0].timeline.xppermindeltas.twentytothirty != undefined) { tl_arr_xppm_twenty_thirty[i] = data.matches[i].participants[0].timeline.xppermindeltas.twentytothirty; }else{ tl_arr_xppm_twenty_thirty[i] = 0; } if(data.matches[i].participants[0].timeline.xppermindeltas.thirtytoend != undefined){ tl_arr_xppm_thirty_end[i] = data.matches[i].participants[0].timeline.xppermindeltas.thirtytoend; }else{ tl_arr_xppm_thirty_end[i] = 0; } tl_arr_gpm_zero_ten[i] = data.matches[i].participants[0].timeline.goldpermindeltas.zerototen; tl_arr_gpm_ten_twenty[i] = data.matches[i].participants[0].timeline.goldpermindeltas.tentotwenty; if(data.matches[i].participants[0].timeline.goldpermindeltas.twentytothirty != undefined){ tl_arr_gpm_twenty_thirty[i] = data.matches[i].participants[0].timeline.goldpermindeltas.twentytothirty; }else{ tl_arr_gpm_twenty_thirty[i] = 0; } if(data.matches[i].participants[0].timeline.goldpermindeltas.thirtytoend != undefined){ tl_arr_gpm_thirty_end[i] = data.matches[i].participants[0].timeline.goldpermindeltas.thirtytoend; }else{ tl_arr_gpm_thirty_end[i] = 0; } //v1.0.2 csarray[i] = data.matches[i].participants[0].stats.minionskilled; assistarray[i] = data.matches[i].participants[0].stats.assists; killarray[i] = data.matches[i].participants[0].stats.kills; gametimearray[i] = data.matches[i].matchduration; championarray[i] = data.matches[i].participants[0].championid; deatharray[i] = data.matches[i].participants[0].stats.deaths; junglecsarray[i] = data.matches[i].participants[0].stats.neutralminionskilledteamjungle; counterjunglecsarray[i] = data.matches[i].participants[0].stats.neutralminionskilledenemyjungle; rolearray[i] = data.matches[i].participants[0].timeline.role; lanearray[i] = data.matches[i].participants[0].timeline.lane; crowdcontrolarray[i] = data.matches[i].participants[0].stats.totaltimecrowdcontroldealt; switch (rolearray[i]) { case "duo": case "solo": //assumes top lane duo player or solo mid or solo top calculatehmc(1.33, 1, 0.5, 0.06, 0.11, 0.17, 5, 0.5, 4, 0.5, 0.16, 0.65, 2, 1.25, 3, 1.5, 1, 0.9, 0.8, 0.7, 1, 1.1, 1.1, 1.1, 1, 1.1, 1.2, 1.3, i); break; case "duo_carry": //assumes bot lane adc calculatehmc(1.33, 1, 0.5, 0.06, 0.11, 0.17, 5, 0.5, 4, 0.5, 0.16, 0.65, 2, 1.25, 3, 2, 1, 0.9, 0.8, 0.7, 0.8, 0.8, 0.8, 0.8, 1, 1.1, 1.2, 1.3, i); break; case "duo_support": //assumes bot lane support calculatehmc(1.33, 1, 0.75, 0.06, 0.11, 0.17, 0.5, 5, 4, 0.5, 0.16, 0.65, 2, 1.25, 0.25, 3.5, 0.1, 0.1, 0.1, 0.1, 0.8, 0.8, 0.8, 0.8, 0.3, 0.4, 0.5, 0.6, i); break; case "none": //assumes jungle, check lane calculatehmc(1.33, 1, 0.5, 0.06, 0.11, 0.17, 2, 2.5, 4, 0.5, 0.16, 0.65, 2, 1.25, 1.5, 1.5, 0.6, 0.5, 0.4, 0.3, 1, 0.9, 0.8, 0.7, 1, 0.9, 0.8, 0.7, i); break; } } } });
if comment switch out, loop works.
i have tried re-writing loop make sure wasnt syntax error in loop declaration that's not case.
i need loop loop 10 times , call calculatehmc function 10 times, it's doing once.
as switch (rolearray[i]) commented out, loop works, doesn't call teh function.
any ideas why happen?
i'm going hazard guess global variable i
using in for
statement getting trounced calculatehmc()
leading premature termination of for
loop.
in case, change for
statement use local variable rather implicit global:
for (var = 0; < 10; i++)
and, inspect calculatehmc()
similar issue. if not issue in code, issue should fixed.
in fact, if run code in strict mode, point of these out errors is, of course, 1 of reasons using strict mode can't accidentally make these kinds of errors.
Comments
Post a Comment