mercredi 4 avril 2018

issue with If statements where both are being returned instead of 1 or the other

I'm having the problem that both parts of my IF statement are being returned rather than one or the other.

I'm trying to get it so that IF $value is in response run 1st IF statement if false return 2nd IF statement but as it stand it seems to be running both of them.

$(document).ready(function() {
  for (var i = 0; i < 12; i++) {
    var row = $('<tr>').appendTo("#zoning tbody");
    for (var j = 1; j < 11; j++) {
      $(`<td class='${i * 10 + j}'>${i * 10 + j}</td>`).appendTo(row);
    }
  }

  function updateTable() {
    $.get('php/test2.php', function(response) {
      console.log(response, );
      if (response.includes("location")) {
        $.each(response, function(index, item) {
          $(`td.${item.beacon}`).css('background-color', item.location).addClass('coloured');
          if (item.delivery_avg <= 4.00) {
            return $('td.coloured').css({
              'border-color': 'lime',
              'border-width': 'thick'
            }).toggleClass('coloured');
          } else if (item.delivery_avg >= 4.01 && item.delivery_avg <= 7.00) {
            return $('td.coloured').css({
              'border-color': 'orange',
              'border-width': 'thick'
            }).toggleClass('coloured');
          } else if (item.delivery_avg >= 7.01 && item.delivery_avg <= 10.00) {
            return $('td.coloured').css({
              'border-color': 'pink',
              'border-width': 'thick'
            }).toggleClass('coloured');
          } else if (item.delivery_avg >= 10.01) {
            return $('td.coloured').css({
              'border-color': 'red',
              'border-width': 'thick'
            }).toggleClass('coloured');
          }
        });
      } else {
        return console.log("key not found");
        $('td.coloured').css('background-color', '#8F8F8F', {
          'border-color': 'black',
          'border-width': 'thin'
        }).addClass('coloured');
      }
    });
  }
  var updateTableInterval = setInterval(updateTable, 1000);
});

Aucun commentaire:

Enregistrer un commentaire