Jump to content

For nested if help


stevend
 Share

Recommended Posts

Hi,Can anyone help me with the following code please.Not sure what I am doing wrong.

var teamerror=false;for (var i = 0; i < 11; i++){   el = document.getElementById("team" + i);	var firstteam=el.value;	var teamsame=1;	for (var j = 0; j < 11; j++){	el2=document.getElementById("team"+j);	var secteam=el2.value;		if (i!=j){			if (secteam=firsteam){				teamsame=teamsame+1;				}			if(teamsame=3){			teamerror=true;			}		}	}}alert(teamerror);

ThanksSteve

Link to comment
Share on other sites

The reason your code isn't working is because you're using an assigning operator on these lines:if (secteam=firsteam){if(teamsame=3)You have to use a comparative operator:if (secteam == firsteam){if(teamsame == 3)You could simplify this line:teamsame=teamsame+1;to this:teamsame++

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...