title: how to add if else condition into an array in javascript (edited)
body: <p>i have this piece of code:</p>
  
  <pre><code>&lt;script  type="text/javascript"&gt;
  function CompareDates(id)
  {
  var months = new Array(12);
   months[1]=  "Jan";
   months[2] = "Feb";
   months[3] = "Mar";
   months[4] = "Apr";
   months[5] = "May";
   months[6] = "Jun";
   months[7] = "Jul";
   months[8]=  "Aug";
   months[9] = "Sep";
   months[10] = "Oct";
   months[11] = "Nov";
   months[12] = "Dec";
  
  
  var d = new Date(id);
  
  var retVal =d.getDate()+' '+ months[d.getDate()]+' '+d.getFullYear()
  return retVal; } 
  
  &lt;/script&gt;
  </code></pre>
  
  <p>and calendar tag:</p>
  
  <pre><code>&lt;p:calendar 
  id="testDate" 
  styleClass="calendar"
  pattern="d MMM yyyy"
  maxlength="10"
  onfocus="$(this).mask('99/99/9999');"
  onchange="$(this).val(CompareDates($(this).val()))"
  &gt;
  &lt;p:watermark for="testDate" value="dd/mmm/yyyy" /&gt;
  &lt;/p:calendar&gt;
  </code></pre>
  
  <p>and i need to add an if/else statement in it so that if date is >31 and months is >12, the date will return 'false' as for now, </p>
  
  <p>it returns 'NaN undefined NaN'</p>
  
  <p>Can someone tell me where and how should i add the condition in?</p>
  
  <p>I did this:</p>
  
  <pre><code>var d = new Date(id);
  
  if (d.getDate &gt; '31' || months &gt; '12'){
  return false;
  
  } else {
  var retVal =d.getDate()+' '+ months[d.getDate()]+' '+d.getFullYear()
  return retVal; } 
  }
  </code></pre>
  
  <p>and result is, even if the date is within the limit it'll still return false.</p>