Comparison with if

0

Personal what is wrong in the code, I made a function that calls a css if a value is greater than 5, the higher value works but the lower one would be 3 where it would appear another css does not work follow the code

SetInterval(function () {
roundedValue = Math.round( parseFloat( sensorValor ) * 100) / 100;
// roundedValue = math.round(parseFloat($('#testValue').val()( * 100 / 100;
if ((roundedValue >= 5) $$ testEnable ) {
$('#pag-1').hide();
$('#pag-2').show();
testEnable = false;
consolo.Log('teste ok!')
}

if ((roundedValue <= 3) $$ testEnable ) {
$('#pag-1').hide();
$('#pag-4').show();
testEnable = false;
consolo.Log('teste ok!')
}

Is there anything wrong in comparative?

    
asked by anonymous 14.06.2017 / 19:00

3 answers

1

I believe the code would look correct as follows:

SetInterval(function () {
    roundedValue = Math.round( parseFloat( sensorValor ) * 100) / 100;
    // roundedValue = math.round(parseFloat($('#testValue').val()( * 100 / 100);
    if (roundedValue >= 5 && testEnable ) {
        $('#pag-1').hide();
        $('#pag-2').show();
        testEnable = false;
        console.log('teste ok!')
    }

    else if (roundedValue <= 3 && testEnable ) {
        $('#pag-1').hide();
        $('#pag-4').show();
        testEnable = false;
        console.log('teste ok!')
    }
});
    
14.06.2017 / 19:39
1

I think you should replace your code with this:

SetInterval(function() {
  roundedValue = Math.round(parseFloat(sensorValor) * 100) / 100;
  // roundedValue = math.round(parseFloat($('#testValue').val()( * 100 / 100;
  if (roundedValue >= 5 && testEnable) {
    $('#pag-1').hide();
    $('#pag-2').show();
    testEnable = false;
    console.Log('teste ok!')
  }

  if (roundedValue <= 3 && testEnable) {
    $('#pag-1').hide();
    $('#pag-4').show();
    testEnable = false;
    console.Log('teste ok!')
  }
});

Young Embrace.

    
14.06.2017 / 19:18
1

It's hard to know what you want to do with this code, but I think the code below can help.

(function () {
  var value = 4;
  var pag1 = document.getElementById("pag-1");
  var pag2 = document.getElementById("pag-2");
  var pag4 = document.getElementById("pag-4");
  
  var onChange = function (oldValue, newValue) {
    pag1.classList.toggle("hide", newValue != 4);
    pag2.classList.toggle("hide", newValue <= 4);
    pag4.classList.toggle("hide", newValue >= 4);
  };
  Object.defineProperty(window, "sensorValor", {
    get: function () { return value; },
    set: function (newValue) { 
      if (value != newValue) {
        onChange(value, newValue);
        value = newValue; 
      }
    }
  });
})();

var sensor = document.getElementById("sensor");
sensor.addEventListener("input", function (event) {
  sensorValor = parseInt(sensor.value);
});
.hide {
  display: none;
}
<input id="sensor" type="text" value="4" />

<div id="pag-1">Pagina 1</div>
<div id="pag-2" class="hide">Pagina 2</div>
<div id="pag-4" class="hide">Pagina 4</div>

In the above example there is a monitoring of the changes of the variable sensorValor , so every lifetime that has its value changed, a function will be sensitized.

input#sensor with event input is only used to demonstrate behavior after updating the value of sensorValor .

    
14.06.2017 / 20:36