title: SetInterval() with "if" condition in js function
body: <p>I would like to continuously call the function below using <code>setInterval()</code> but only if the condition in the if statement evaluates to true. 
  <strong>Note:</strong> The function is global.</p>
  
  <pre><code>function view_stack(){
      if(my_stack.size() &gt; 0){
          document.getElementById("stack_visual").innerHTML = my_stack.view();
      } else {
          swal("Ohhhh Noes", "There are no items in the stack!", "error");
      }
  }      
  </code></pre>
  
  <p>Is there a way I can achieve it? </p>