title: make the average with 2 values from Json with AngularJS
body: <p>I got one problem because I don't know exactly how to do this.</p>
  
  <p>I have one JSON and I want to make the average using two values from JSON</p>
  
  <p>JSON</p>
  
  <pre><code>[
          {
              "player": {
                "info": {
                  "position": "D",
                  "shirtNum": 4,
                  "positionInfo": "Centre/Right Central Defender"
                },
                "nationalTeam": {
                  "isoCode": "BE",
                  "country": "Belgium",
                  "demonym": "Belgian"
                },
                "age": "27 years 139 days",
                "name": {
                  "first": "Toby",
                  "last": "Alderweireld"
                },
                "id": 4916,
                "currentTeam": {
                  "name": "Tottenham Hotspur",
                  "teamType": "FIRST",
                  "shortName": "Spurs",
                  "id": 21
                }
              },
              "stats": [
                {
                  "name": "goals",
                  "value": 5
                },
                {
                  "name": "losses",
                  "value": 20
                },
                {
                  "name": "wins",
                  "value": 48
                },
                {
                  "name": "draws",
                  "value": 23
                },
                {
                  "name": "fwd_pass",
                  "value": 1533
                },
                {
                  "name": "goal_assist",
                  "value": 2
                },
                {
                  "name": "appearances",
                  "value": 80
                },
                {
                  "name": "mins_played",
                  "value": 6953
                },
                {
                  "name": "backward_pass",
                  "value": 308
                }
              ]
            }]
  </code></pre>
  
  <p>I made one function in AngularJS but I don't know if is good or I'm calling in the HTML good to show the average between the value of goals and the mins_played.</p>
  
  <p>The function in Angular what I did is this</p>
  
  <pre><code>$scope.mediaGoals = function () {
          for (var i = 0; i &lt; $scope.Jugador.stats.length; i++) {
              for (var x=0; x&lt; $scope.Jugador.stats[i].stats.length; x++) {
                switch($scope.Jugador.stats[i].stats[x].name) {
                  case 'goals':
                   var tmp_goals = $scope.Jugador.stats[i].stats[x].value;
                  break;
                  case 'mins_played':
                   var tmp_mins = $scope.Jugador.stats[i].stats[x].value;
                  break;
  
                }
              }
              $scope.Jugador.stats[i].media = tmp_goals/tmp_mins;
          }
      }
  </code></pre>
  
  <p>And I made this HTML</p>
  
  <pre><code>&lt;div class="stadistics"&gt;
       &lt;div class="cont-desc-player" ng-repeat="stat in Jugador.stats"&gt;
            &lt;div class="desc-player separador" ng-if="stat.name == 'appearances'"&gt;
                 &lt;span class="txt-estadistics"&gt;Appearances&lt;/span&gt;
                 &lt;span class="num-estadistics"&gt;{{stat.value}}&lt;/span&gt;
             &lt;/div&gt;
             &lt;div class="desc-player separador" ng-if="stat.name == 'goals'"&gt;
                  &lt;span class="txt-estadistics"&gt;Goals&lt;/span&gt;
                  &lt;span class="num-estadistics"&gt;{{stat.value}}&lt;/span&gt;
             &lt;/div&gt;
             &lt;div class="desc-player separador" ng-if="stat.name == 'goal_assist'"&gt;
                  &lt;span class="txt-estadistics"&gt;Assists&lt;/span&gt;
                  &lt;span class="num-estadistics"&gt;{{stat.value}}&lt;/span&gt;
             &lt;/div&gt;
             &lt;div class="desc-player separador" ng-if="stat.mediaGoals()"&gt;
                  &lt;span class="txt-estadistics"&gt;Goals per match&lt;/span&gt;
                  &lt;span class="num-estadistics"&gt;{{stat.media}}&lt;/span&gt;
             &lt;/div&gt;
        &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Please, can you help me with it?, because I don't know if I made the function good and it doesn't show anything.</p>