How to check an *if* condition for 5 seconds? This *if* condition should be true for 5 seconds to execute its code. 

```
function checkcodition() {
  var a,b;
  if (a == 0 && b == 1) // <--this condition should be true for 5 seconds ??
  {
    console.log(" This line should display after 5 seconds");
  }
}

```

EDIT :

```js
function valupdate() {
  $('p').each(function(index, element) {
    var number = Math.round(Math.random());
    $(element).text(number);
  });
}
valupdate();

// cache DOM elements for quick reference
var demo1 = $('#demo1');
var demo2 = $('#demo2');
var demo3 = $('#demo3');

// store their current values in object
// this is how we will reference their previous values
var stored_values = {
  demo1: demo1.text(),
  demo2: demo2.text(),
  demo3: demo3.text()
};

// loop through all elements
// get their current value from .text()
// get their PREVIOUS value from the object we made above
// compare values with our custom compare function (define below)
// finally, save the current value in our object
function checkValues(item, msg) {
  var element_id = item.attr('id');
  var currentValue = item.text();
  var previousValue = stored_values[element_id];
  compareValues(currentValue, previousValue, element_id, msg);
  stored_values[element_id] = currentValue;
}

// compare values passed in, and determine what to do
function compareValues(current, previous, elementID, smstext) {
  if (previous == 0 && current == 1) //check conditions for 5 seconds to execute below code.
  {
    console.log('Sending SMS for : ' + elementID + ':' + smstext + '!!!');
  }
  else {
    return; // do nothing
  }
}

var msg1 = "Message1";
var msg2 = "Message2";
var msg3 = "Message3";

setInterval(function() {
  valupdate();
}, 1000);

setInterval(function() {
  checkValues(demo1, msg1);
  //checkValues(demo2,msg2);
  //checkValues(demo3,msg3);
}, 5000);
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<h2>Test SMS Triggers</h2>

<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
```