title: Javascript | If sentence
body: <p>I dont know javascript but I would like to do something that I dont know how. In this code these lines repeat constantly:</p>
  
  <pre><code>    if (jsonLength==0)
  {
  
      html+='&lt;div class="desc"&gt; &lt;div class="thumb"&gt; &lt;img class="img-circle" src="" width="35px" height="35px" align=""&gt; &lt;/div&gt; &lt;div class="details"&gt;&lt;p style="padding-left: 10px;"&gt;&lt;a  href="#"&gt;&lt;/a&gt;&lt;br/&gt;Sê o primeiro a escrever no chat!&lt;/p&gt;&lt;/div&gt; &lt;/div&gt;';
  }
  </code></pre>
  
  <p>How do I stop them from repeating? Full code here</p>
  
  <pre><code>var lastTimeID = 0;
  
  $(document).ready(function() {
      $('#btnSend').click(function(){
          sendChatText();
          $('#chatInput').val("");
      });
      startChat();
  });
  
  function startChat(){
      setInterval(function(){ getChatText(); }, 700);
  
  }
  
  function getChatText(){
      $.ajax({
          type: "GET",
          url: "/refresh.php?lastTimeID="+lastTimeID
      }).done(function( data )
      {
          var jsonData = JSON.parse(data);
          var jsonLength = jsonData.results.length;
          var html = ''; 
  
          for (var i = 0; i &lt; jsonLength; i++) {
              var result = jsonData.results[i];
              html += '&lt;div class="desc"&gt; &lt;div class="thumb"&gt; &lt;img class="img-circle" src="' + result.picture +'" width="35px" height="35px" align=""&gt; &lt;/div&gt; &lt;div class="details"&gt;&lt;p style="padding-left: 10px;"&gt;&lt;a  href="#"&gt;' + result.user_name +'&lt;/a&gt;&lt;br/&gt;'+result.chattext+ '&lt;/p&gt;&lt;/div&gt; &lt;/div&gt;';
              lastTimeID = result.id;
          }
          if (jsonLength==0)
  {
  
      html+='&lt;div class="desc"&gt; &lt;div class="thumb"&gt; &lt;img class="img-circle" src="" width="35px" height="35px" align=""&gt; &lt;/div&gt; &lt;div class="details"&gt;&lt;p style="padding-left: 10px;"&gt;&lt;a  href="#"&gt;&lt;/a&gt;&lt;br/&gt;Sê o primeiro a escrever no chat!&lt;/p&gt;&lt;/div&gt; &lt;/div&gt;';
  }
          $('#view_ajax').append(html);
  
      });
  }
  
  function sendChatText(){
      var chatInput = $('#chatInput').val();
      if(chatInput != ""){
          $.ajax({
              type: "GET",
              url: "/submit.php?chattext=" + encodeURIComponent( chatInput )
          });
      }
  }
  </code></pre>
  
  <p>It has some php parts, but I dont think that they are usefull for this question</p>
  
  <p>Thanks in advance</p>