Solved

IF statement combined with && incorrect syntax for NFL scoreboard

Posted on 2013-06-10
14
392 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
That seems to be the right point; could you perhaps post which is the exact error you get?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
} else if {

is not correct syntax either
0
 

Author Comment

by:powerztom
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You are welcome :)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

771 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

10 Experts available now in Live!

Get 1:1 Help Now