title: What if if statement is not executed and does not recognize numerical data from the date format?
body: <p>A user suppose to enter the date and based on the date entered the code determines which day of the week was at that specific date?</p>
  <p>The code successfully recognize the day of the week and recognize that each month has 31 days, so if I enter February 31, it automatically recognizes as March 3 if the year is simple, and as March 2 if the year is leap! If I enter some gibberish let's say 2019-15-34 it returns as NaN!</p>
  <p>I set up conditions for each month that if the month is January maximal number of days should not surpass 31, and if the month is February maximal number of days should not surpass 28 if the year is simple, and so on for each month. After that I set up alert to show the message &quot;Your data is invalid! Please enter valid data!&quot; and set up continue thereafter to return eventual user to reenter the data this time valid date. If date is valid (the month is not suppose to be greater than 12, and date suppose not to be greater than 31) it suppose to show up the message &quot;OK!Your data is valid!&quot; and the code to continue with execution and to get out of if statement!</p>
  <p>However it's evident that even when I enter some date that does not make sense let's say 2019-15-15 the code does not return &quot;Your data is invalid! Please enter valid data!&quot;, but no matter of what I enter it comes out &quot;OK! Your date is valid!&quot;.</p>
  <p>What's wrong and why if statement does not recognize date and month format and does not properly execute the code?</p>
  <p>Here is the code:</p>
  <pre><code>var flag = false;
  while(!flag){
      var anydate = prompt('Enter any date in format yyyy-mm-dd', anydate);
      anydate = new Date(anydate);
      var dd = anydate.getDate();
      var mm = (anydate.getMonth()+1);
      var yyyy = anydate.getFullYear();
      if(((mm&lt;1)||(mm&gt;12)||((mm===1)&amp;&amp;(dd&gt;31))||((mm===2)&amp;&amp;(dd&gt;28))||((mm===3)&amp;&amp;(dd&gt;31))|| ((mm===4)&amp;&amp;(dd&gt;30))||((mm===5)&amp;&amp;(dd&gt;31))||((mm===6)&amp;&amp;(dd&gt;30))||((mm===7)&amp;&amp;(dd&gt;31))||((mm===8)&amp;&amp;(dd&gt;31))||((mm===9)&amp;&amp;(dd&gt;30))||((mm===10)&amp;&amp;(dd&gt;31))||((mm===11)&amp;&amp;(mm&gt;30))||((mm===12)&amp;&amp;(dd&gt;31)))){
          alert('Your data is invalid! Enter valid date please!');
          continue;
          flag = false}else{
          alert('OK! You can continue with process!');
          break;
      };
  };
  
  var weekday = new Array(7);
  weekday[0] = &quot;Sunday&quot;;
  weekday[1] = &quot;Monday&quot;;
  weekday[2] = &quot;Tuesday&quot;;
  weekday[3] = &quot;Wednesday&quot;;
  weekday[4] = &quot;Thursday&quot;;
  weekday[5] = &quot;Friday&quot;;
  weekday[6] = &quot;Saturday&quot;;
  
  console.log(weekday[anydate.getDay()]);
  console.log(anydate.getMonth()+1);
  console.log(anydate.getDate());
  console.log(anydate.getFullYear());
  a = anydate
  anydate = mm + '-' + dd + '-' + yyyy;
  console.log(anydate);
  </code></pre>