Trying to change team javascript baseball program -
i using code.org
javascript library. i'm trying have changes team based on 2 selected once 3 outs reached. tried declare team1
, team2
, setting them equal check box selected doesnt work correctly.
the team name doesn't change on label when first select team. i'm not quite sure how main goal team name change when current team gets 3 outs. there label being used in player selection function displays 1st team selected.
var outs = 0; var team1 = ""; var team2 = ""; var strikes = 0; var balls = 0; var fouls = 0; var inning = 0; var hit = 0; var currentplayer = team1, team2; //player selection onevent("btnstart","click", function() { var chkboxs = ["yankees", "boston", "astros"]; var selected = []; (var index = 0; selected.length < 2 && index < chkboxs.length; index++) { if (getchecked(chkboxs[index])) { selected.push(index); } } setscreen("game"); if (selected.length == 2) { console.log("the teams are: " + chkboxs[selected[0]] + " , " + chkboxs[selected[1]]); } if (chkboxs[selected[0]]) { settext("lblteamgame",chkboxs[selected[0]]); team1 = chkboxs[selected[0]]; team2 = chkboxs[selected[1]]; } else { settext("lblteamgame",chkboxs[selected[1]]); } }); //pitching rules function count() { if (balls == 4) { console.log("walk"); settext("lblballcount", 0); settext("lblstrikecount", 0); balls = 0; strikes = 0; } if (strikes == 3) { console.log("strike out"); outs++; settext("lblstrikecount", 0); settext("lbloutcount", outs); settext("lblballcount", 0); strikes = 0; balls = 0; } if (outs == 3) { inning++; settext("lblinningcount", inning); switchplayer(); } if(hit) { settext("lblstrikecount", 0); settext("lblballcount", 0); strikes = 0; balls = 0; } } //switch teams function switchplayer() { if(currentplayer == team1) { currentplayer = team2; showelement("player2_highlight"); hideelement("player1_highlight"); } else { showelement("player1_highlight"); hideelement("player2_highlight"); currentplayer = 1; } console.log("current player is: " + currentplayer); }
this problem:
function switchplayer(){ if(currentplayer==team1){ currentplayer=team2; showelement("player2_highlight"); hideelement("player1_highlight"); } else { showelement("player1_highlight"); hideelement("player2_highlight"); currentplayer=team1; // specify team1 instead of 1 } console.log("current player is: "+currentplayer); }
also, after switching teams, need reset number of outs.
if(outs==3) { inning++; settext("lblinningcount",inning); switchplayer(); outs=0; }
Comments
Post a Comment