Solved

IF statement combined with && incorrect syntax for NFL scoreboard

Posted on 2013-06-10
14
394 Views
Last Modified: 2013-06-12
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
0
Comment
Question by:powerztom
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 9

Expert Comment

by:Ishaan Rawat
ID: 39234652
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

0
 

Author Comment

by:powerztom
ID: 39234714
Still not correct your code is identical to mine In Html file something is missing. But thanks for your help.
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39237054
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) }
0
 

Author Comment

by:powerztom
ID: 39237765
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
0
 
LVL 21

Expert Comment

by:Craig Wagner
ID: 39241423
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.
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39241450
That seems to be the right point; could you perhaps post which is the exact error you get?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39241510
} else if {

is not correct syntax either
0
 

Author Comment

by:powerztom
ID: 39241771
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

0
 
LVL 82

Expert Comment

by:hielo
ID: 39241846
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

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 39241861
Looks like wishful thinking - the code is a complete mess.

This is less of a mess, maybe not correct logic according to the data  but syntactically correct

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

Open in new window

0
 

Author Closing Comment

by:powerztom
ID: 39242022
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
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39242143
You are welcome :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now