Link to home
Start Free TrialLog in
Avatar of Tom Powers
Tom Powers

asked on

IF statement combined with && incorrect syntax for NFL scoreboard

I created a Nfl Scoreboard the last issue I have with it is I created a down and yards to go statement it needs awayteam to have team id and a offense id to equal each other the same goes for hometeam. I constructed it the way that made sense using if team = away && Team id== off id

if ($(Team).attr('vh') == "A") && ($(Team).attr('ID') == ($(Play).attr('OffID')
  var Play = $(d.find('Play'));
  var RD = Play.attr('ResultingDown') ;
  $('#VRd').html(RD);
  var Rtg = Play.attr('ResultingToGo') ;
  $('#VRtg').html(Rtg);
else if 
if ($(Team).attr('vh') == "H") && ($(Team).attr('ID') == ($(Play).attr('OffID')
 var Play = $(d.find('Play'));
 var RD = Play.attr('ResultingDown') ;
 $('#Hrd').html(RD);
 var Rtg = Play.attr('ResultingToGo') ;
 $('#HRtg').html(Rtg);

Open in new window

What is wrong with this it makes sense to me but then I'm not EE. Hardcode 166 xml that is Green bay and 90 xml is Philadelphia.
Top.html
AB-3171-166.xml
AB-3171-90.xml
Avatar of Ishaan Rawat
Ishaan Rawat
Flag of India image

If Team & Play are variable... then... try the following..

if (Team.attr('vh') == "A") && (Team.attr('ID') == (Play.attr('OffID') {
 var Play = $(d.find('Play'));		
var RD = Play.attr('ResultingDown') ;
        $('#VRd').html(RD);
		var Rtg = Play.attr('ResultingToGo') ;
        $('#VRtg').html(Rtg);
       }
		else if {
		if (Team.attr('vh') == "H") && (Team.attr('ID') == (Play.attr('OffID')
 var Play = $(d.find('Play'));		
var RD = Play.attr('ResultingDown') ;
        $('#Hrd').html(RD);
		var Rtg = Play.attr('ResultingToGo') ;
        $('#HRtg').html(Rtg);}

Open in new window

Avatar of Tom Powers
Tom Powers

ASKER

Still not correct your code is identical to mine In Html file something is missing. But thanks for your help.
I think that the && condition must be placed inside brackets, that is to say:
if (($(Team).attr('vh') == "A") && ($(Team).attr('ID') == $(Play).attr('OffID'))) { (code) }
} else { (code) }
Made a Change based on firebug output here now only down and yards come up on Green Bay not Philadelphia

var Play = $(d.find('Play'));
	var Team = $(d.find('Team'));
		 	if (($(Team).attr('vh') == "A") && ($(Team).attr('ID') == $(Play).attr('OffID')))	{
		

       
		var RD = Play.attr('ResultingDown') ;
        $('#VRd').html(RD);
		var Rtg = Play.attr('ResultingToGo') ;
        $('#VRtg').html(Rtg);
	}
	 var Play = $(d.find('Play'));
		var Team = $(d.find('Team'));
		if (($(Team).attr('vh') == "H") && ($(Team).attr('ID') == $(Play).attr('OffID'))) {
			
		var HD = Play.attr('ResultingDown') ;
        $('#Hrd').html(HD);
		var Htg = Play.attr('ResultingToGo') ;
        $('#HRtg').html(Htg);
	}

Open in new window


Stuck in the mud!
Top.html
Avatar of Craig Wagner
It looks to me like you've got mismatched parenthesis on this line.

if ($(Team).attr('vh') == "H") && ($(Team).attr('ID') == ($(Play).attr('OffID')

You're also getting yourself in trouble by not using braces to block your if statement blocks. Here is your code from the HTML file:

		if ($(Team).attr('vh') == "A" && ($(Team).attr('ID')) == ($(Play).attr('OffID')))
		var RD = Play.attr('ResultingDown') ;
        $('#VRd').html(RD);
		var Rtg = Play.attr('ResultingToGo') ;
        $('#VRtg').html(Rtg);
        var Play = $(d.find('Play'));
		else if 
		if ($(Team).attr('vh') == "H") && ($(Team).attr('ID') == ($(Play).attr('OffID')
		var RD = Play.attr('ResultingDown') ;
        $('#Hrd').html(RD);
		var Rtg = Play.attr('ResultingToGo') ;
        $('#HRtg').html(Rtg);
        var Play = $(d.find('Play'));

Open in new window


Here's what it probably should look like:

    if $(Team).attr('vh') == "A" && $(Team).attr('ID') == $(Play).attr('OffID')) {
        var RD = Play.attr('ResultingDown') ;
        $('#VRd').html(RD);
        var Rtg = Play.attr('ResultingToGo') ;
        $('#VRtg').html(Rtg);
        var Play = $(d.find('Play'));
    } else if {
        if $(Team).attr('vh') == "H" && $(Team).attr('ID') == $(Play).attr('OffID')) {
            var RD = Play.attr('ResultingDown') ;
            $('#Hrd').html(RD);
            var Rtg = Play.attr('ResultingToGo') ;
            $('#HRtg').html(Rtg);
            var Play = $(d.find('Play'));
    }

Open in new window


Two problems that are probably making this really hard to debug:

You are using a mix of spaces and tabs for indentation so the indentation is inconsistent making the code really hard to read
You are over-parenthesizing the code. Something like $(Team).attr('vh') == "H" doesn't need to be wrapped in parenthesis.
That seems to be the right point; could you perhaps post which is the exact error you get?
} else if {

is not correct syntax either
Syntax Error at 124 in Dreamwaever firebug loadData not defined confused! It used to almost work.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>The Sports Network</title>
<style type="text/css">
.formatcell {
	text-align: center;
	vertical-align: top;
}
.formatcelldown {
	text-align: center;
	vertical-align: bottom;
}
.formatcellcenter {
	text-align: center;
	vertical-align: middle;
}
.tablecolor {
	background-image: url(Greywall.png);
}
.tablecolor tr .formatcell #imgHomeHelmet {
	color: #FFF;
}
.rr {
	background-color: #FFF;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
  var xmlPath = '.'; // '/xml/nfl/scores/real';
  var xmlGameID = 'AB-3171'; // game id only, _counter.xml will be added in the ajax call
  var counterXml = 0;

  var teamNames = {
    "079": "GIANTS",
    "068": "LIONS",
    "084": "49ERS",
    "063": "BEARS",
    "083": "CHARGERS",
    "085": "SEAHAWKS",
    "088": "REDSKINS",
    "061": "FALCONS",
    "062": "BILLS",
    "064": "BENGALS",
    "065": "RAVENS",
    "066": "COWBOYS",
    "067": "BRONCOS",
    "069": "PACKERS",
    "070": "TITANS",
    "071": "COLTS",
    "072": "CHIEFS",
    "073": "RAIDERS",
    "074": "RAMS",
    "075": "DOLPHINS",
    "076": "VIKINGS",
    "077": "PATRIOTS",
    "078": "SAINTS",
    "080": "JETS",
    "081": "EAGLES",
    "082": "STEELERS",
    "086": "CARDINALS",
    "087": "BUCS",
    "089": "PANTHERS",
    "090": "JAGUARS",
    "120": "BROWNS",
    "151": "TEXANS",
    "685": "A-F-C",
    "686": "N-F-C"
  };

  $(document).ready(function(){
    $.ajax({
      type: "GET",
      url:  xmlPath+"/"+xmlGameID+"_0.xml",
      dataType: "xml",
      success: function(data){
        var d = $(data);
        d.find('Team').each(function(i,Team){
          var team=$(Team);
          var id = team.attr("ID").toLowerCase();
          var teamname = team.attr("name");
          var homeOrAway = team.attr("vh");
          var selector1 = (homeOrAway=="A") ? '#Visitor' : '#Hometeam' ;
          var selector2 = (homeOrAway=="A") ? '#VTeamname' : '#HTeamName' ;
          
		  $(selector1).html(teamname);
          $(selector2).html(teamNames[id]);
		   
          
		  
        });
      }
    });
  });

  function loadData() {
    $.ajax({
      type: "GET",
      url:  xmlPath+"/"+xmlGameID+'_'+counterXml+".xml",
      dataType: "xml",
      success: function(data){
        var d = $(data);
        d.find('Team').each(function(i,Team){
          if ($(Team).attr('vh') == "A") {
            $('#imgVisitHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_away.png");
		  }
          if ($(Team).attr('vh') == "A") {
			  $(d.find('Team'))
		  var VS1 = $(Team).find('Linescore');
		  var vs2 = VS1.attr('Score');
		  $('#VS').html(vs2);}
          if ($(Team).attr('vh') == "H") {
            $('#imgHomeHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/'+$(Team).attr('ID')+"_helmet_home.png");
         }
		 if ($(Team).attr('vh') == "H") {
			 $(d.find('Team'))
		   var HS1 = $(Team).find('Linescore');
		  var hs2 = HS1.attr('Score');
		  $('#HS').html(hs2); 
		 }
        });
	 var Play = $(d.find('Play'));
 var Team = $(d.find('Team));
		 if $(Team).attr('vh') == "A" && $(Team).attr('ID') == $(Play).attr('OffID')) {
        var RD = Play.attr('ResultingDown') ;
        $('#VRd').html(RD);
        var Rtg = Play.attr('ResultingToGo') ;
        $('#VRtg').html(Rtg);
        var Play = $(d.find('Play'));
		  }
        });
var Play = $(d.find('Play'));
 var Team = $(d.find('Team));
        if $(Team).attr('vh') == "H" && $(Team).attr('ID') == $(Play).attr('OffID')) {
            var RD = Play.attr('ResultingDown') ;
            $('#Hrd').html(RD);
            var Rtg = Play.attr('ResultingToGo') ;
            $('#HRtg').html(Rtg);
            var Play = $(d.find('Play'));
   }
        });
        // changed all below to just use the variables that contain the text directly, as the arrays do not exist and don't seem necessary in this situation
		
		
        var inn = Play.attr('TimeLeft') ;
        $('#Time').html(inn ); // timeleft[inn]
        var bo = Play.attr('BallYrd') ;
        $('#Ballon').html(bo ); // ballyrd[bo]
        var dn = Play.attr('ResultingDown') ;
        $('#Down').html(dn ); // resultingdown[dn]
        var ydtogo = Play.attr('ResultingToGo') ;
        $('#Ydstogo').html(ydtogo ); // resultingtogo[ydtogo]
        var qtr = Play.attr('Quarter') ;
        $('#Q').html(qtr ); // quarter[qtr]
        ++counterXml;
      }
    });
  }
</script>
</head>
<body>
<table width="786" border="1" class="tablecolor">
  <tr>
    <td height="21" colspan="5" class="formatcell" id="Visitor">Visitor</td>
    <td colspan="4" class="formatcell" id="Time">TimeRemaining</td>
    <td colspan="5" class="formatcell" id="Hometeam">Hometeam</td>
  </tr>
  <tr>
    <td width="78" height="64" bgcolor="#FFFFFF"><p align="center" class="rr"><img src="VistorHelmet.png" name="imgVisitHelmet" width="63" height="62" class="formatcellcenter" id="imgVisitHelmet"></p></td>
    <td width="87" colspan="3" class="formatcellcenter" id="VTeamname">Teamname</td>
    <td width="74" class="formatcellcenter"><strong id="VS">VistorScore</strong></td>
    <td width="71" class="formatcellcenter">Ball on</td>
    <td width="65" class="formatcellcenter">Down</td>
    <td width="62" class="formatcellcenter">Yds to go</td>
    <td width="59" class="formatcellcenter">Quarter</td>
    <td width="74" class="formatcellcenter"><strong id="HS">HomeScore</strong></td>
    <td width="82" colspan="3" class="formatcellcenter" id="HTeamName">TeamName</td>
    <td width="70" class="rr"><img src="HomeHelmet.png" name="imgHomeHelmet" width="66" height="61" class="formatcellcenter" id="imgHomeHelmet"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="formatcell" id="VRd">Rd  </td>
    <td class="formatcell">&amp;</td>
    <td class="formatcell" id="VRtg">Rtg</td>
    <td>&nbsp;</td>
    <td class="formatcell" id="Ballon">Ballon</td>
    <td class="formatcell" id="Down">Down</td>
    <td class="formatcell" id="Ydstogo">Ydstogo</td>
    <td class="formatcell" id="Q">Q</td>
    <td class="formatcell">&nbsp;</td>
    <td class="formatcell" id="Hrd">Rd </td>
    <td class="formatcell">&amp;</td>
    <td class="formatcell" id="HRtg">Rtg</td>
    <td class="formatcell">&nbsp;</td>
  </tr>
</table>
<p id="demo"></p>
<script>
var myVar=setInterval(function(){myTimer()},1000);

function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
loadData();
//checkStatus();
}
</script>
</body>
</html>

Open in new window

Try:
  var xmlPath = '.'; // '/xml/nfl/scores/real';
  var xmlGameID = 'AB-3171'; // game id only, _counter.xml will be added in the ajax call
  var counterXml = 0;

  var teamNames = {
  	"079": "GIANTS",
  	"068": "LIONS",
  	"084": "49ERS",
  	"063": "BEARS",
  	"083": "CHARGERS",
  	"085": "SEAHAWKS",
  	"088": "REDSKINS",
  	"061": "FALCONS",
  	"062": "BILLS",
  	"064": "BENGALS",
  	"065": "RAVENS",
  	"066": "COWBOYS",
  	"067": "BRONCOS",
  	"069": "PACKERS",
  	"070": "TITANS",
  	"071": "COLTS",
  	"072": "CHIEFS",
  	"073": "RAIDERS",
  	"074": "RAMS",
  	"075": "DOLPHINS",
  	"076": "VIKINGS",
  	"077": "PATRIOTS",
  	"078": "SAINTS",
  	"080": "JETS",
  	"081": "EAGLES",
  	"082": "STEELERS",
  	"086": "CARDINALS",
  	"087": "BUCS",
  	"089": "PANTHERS",
  	"090": "JAGUARS",
  	"120": "BROWNS",
  	"151": "TEXANS",
  	"685": "A-F-C",
  	"686": "N-F-C"
  };

  $(document).ready(function ()
  {
  	$.ajax(
  	{
  		type: "GET",
  		url: xmlPath + "/" + xmlGameID + "_0.xml",
  		dataType: "xml",
  		success: function (data)
  		{
  			var d = $(data);
  			d.find('Team').each(function (i, Team)
  			{
  				var team = $(Team);
  				var id = team.attr("ID").toLowerCase();
  				var teamname = team.attr("name");
  				var homeOrAway = team.attr("vh");
  				var selector1 = (homeOrAway == "A") ? '#Visitor' : '#Hometeam';
  				var selector2 = (homeOrAway == "A") ? '#VTeamname' : '#HTeamName';

  				$(selector1).html(teamname);
  				$(selector2).html(teamNames[id]);

  			});
  		}
  	});
  });

  function loadData()
  {
  	$.ajax(
  		{
  			type: "GET",
  			url: xmlPath + "/" + xmlGameID + '_' + counterXml + ".xml",
  			dataType: "xml",
  			success: function (data)
  			{
  				var d = $(data);
  				d.find('Team').each(function (i, Team)
  				{
  					if ($(Team).attr('vh') == "A")
  					{
  						$('#imgVisitHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/' + $(Team).attr('ID') + "_helmet_away.png");
  					}
  					if ($(Team).attr('vh') == "A")
  					{
  						$(d.find('Team'))
  						var VS1 = $(Team).find('Linescore');
  						var vs2 = VS1.attr('Score');
  						$('#VS').html(vs2);
  					}
  					if ($(Team).attr('vh') == "H")
  					{
  						$('#imgHomeHelmet').attr('src', 'http://images.sportsnetwork.com/nfl/atthegridiron/end_zone/' + $(Team).attr('ID') + "_helmet_home.png");
  					}
  					if ($(Team).attr('vh') == "H")
  					{
  						$(d.find('Team'))
  						var HS1 = $(Team).find('Linescore');
  						var hs2 = HS1.attr('Score');
  						$('#HS').html(hs2);
  					}
  				});
  				var Play = $(d.find('Play'));
  				var Team = $(d.find('Team'));
  				if ($(Team).attr('vh') == "A" && $(Team).attr('ID') == $(Play).attr('OffID'))
  				{
  					var RD = Play.attr('ResultingDown');
  					$('#VRd').html(RD);
  					var Rtg = Play.attr('ResultingToGo');
  					$('#VRtg').html(Rtg);
  					var Play = $(d.find('Play'));
  				}
			}
  		});
  		var Play = $(d.find('Play'));
  		var Team = $(d.find('Team'));
  		if ($(Team).attr('vh') == "H" && $(Team).attr('ID') == $(Play).attr('OffID'))
  		{
  			var RD = Play.attr('ResultingDown');
  			$('#Hrd').html(RD);
  			var Rtg = Play.attr('ResultingToGo');
  			$('#HRtg').html(Rtg);
  			var Play = $(d.find('Play'));
  		}

       // changed all below to just use the variables that contain the text directly, as the arrays do not exist and don't seem necessary in this situation
    
      var inn = Play.attr('TimeLeft');
      $('#Time').html(inn); // timeleft[inn]
      var bo = Play.attr('BallYrd');
      $('#Ballon').html(bo); // ballyrd[bo]
      var dn = Play.attr('ResultingDown');
      $('#Down').html(dn); // resultingdown[dn]
      var ydtogo = Play.attr('ResultingToGo');
      $('#Ydstogo').html(ydtogo); // resultingtogo[ydtogo]
      var qtr = Play.attr('Quarter');
      $('#Q').html(qtr); // quarter[qtr]
      ++counterXml;

  	});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You mplungjan I was starting to lose my mind cause I'd get close then Code became a giant mess. But you stepped in and got it right. Thanks Bro
You are welcome :)