Jump to content

For nested if help


stevend

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...