Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

IF statement combined with && incorrect syntax for NFL scoreboard

Posted on 2013-06-10
14
Medium Priority
?
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 10

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
Plesk WordPress Toolkit

Plesk's WordPress Toolkit allows server administrators, resellers and customers to manage their WordPress instances, enabling a variety of development workflows for WordPress admins of all skill levels, from beginners to pros.

See why 2/3 of Plesk servers use it.

 

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
 
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 2000 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

636 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