title: Could it be accomplished in fewer lines of code and when to avoid using control flow?
body: <p>The task was based on the date entered by a user to determine:</p>
  <ol>
  <li>Whether the date is valid(proper format, plus the month number to not exceed 12, and the date number not to exceed the number of days that each single month have)</li>
  <li>What day of the week that specific day was(or will be)</li>
  <li>Which day in row of that specific year that day was( or will be)</li>
  <li>Whether that specific year is leap or simple year</li>
  <li>Which specific day of the week in row of that specific year and month the day enter was(or will be)?!( Example date 2020-12-31, 31 of December 2020 was Thursday and it was 53 Thursday of the year 2020, and 5 th Thursday of the month of December 2020)</li>
  </ol>
  <p>I resolved the task successfully, but I'm still excessively using control flow and if statements which it seems to me consume me a lot of lines of codes! Could all of this be accomplished by fewer lines of code and without excessive using of control flow? When is unavoidable to use control flow and when it could be avoided? Here is my code:</p>
  <pre><code>var flag = false;
  while(!flag){
      var anydate = prompt('Enter the date!', anydate);
      let parts = anydate.split('-');
      yyyy = Number(parts[0]);
      mm = Number(parts[1]);
      dd = Number(parts[2]);
  if ((yyyy&lt;0)||(mm&lt;1)||(mm&gt;12)||(dd&gt;31)||(typeof(anydate)==='undefined')||(yyyy%1!==0)||  (mm%1!==0)||(dd%1!==0)||((mm===2)&amp;&amp;(dd&gt;29))||((mm===4)&amp;&amp;(dd&gt;30))||((mm===6)&amp;&amp;(dd&gt;30))||((mm===9)&amp;&amp;(dd&gt;30))||((mm===11)&amp;&amp;(dd&gt;30))){
      alert('Your date is invalid! Please enter valid date!');
      continue;
      flag = false;
  }else{
      alert('OK! You can continue with process!');
      break;
  };
  }
  if (yyyy%4===0){
      alert('This is leap year! The month of February has 29 days!');
  }else{
      alert('This is simple year! The month of February has 28 days!');
  }
  anydate = new Date(anydate);
  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;;
  
      dayoftheweek = weekday[anydate.getDay()]
      d = anydate.getDate();
      m = anydate.getMonth();
      console.log(weekday[anydate.getDay()]);
      console.log(anydate.getMonth()+1);
      console.log(anydate.getDate());
      console.log(anydate.getFullYear());
      console.log(anydate);
      var start = new Date(anydate.getFullYear(), 0, 0);
      var diff = (anydate - start) + ((start.getTimezoneOffset() - anydate.getTimezoneOffset()) * 60 * 1000);
      var oneDay = 1000 * 60 * 60 * 24;
      var day = Math.floor(diff / oneDay);
      alert('This is the day ' +  day  + ' of the year!');
      var q = Math.floor(day/7)+1;
      q = Number(q);
      var q1 = Math.floor(d/7)+1;
      q1 = Number(q1);
      if(dayoftheweek==='Friday'){
          alert('This is ' + q + ' Friday of the year and ' + q1 + ' Friday of the month ' + mm);
      }else if(dayoftheweek==='Saturday'){
          alert('This is ' + q + ' Saturday of the year and '+ q1 + ' Saturday of the month '+ mm);
      }else if(dayoftheweek==='Sunday'){
          alert('This is ' + q + ' Sunday of the year and '+ q1 + ' Sunday of the month ' + mm);
      }else if(dayoftheweek==='Monday'){
          alert('This is ' + q + ' Monday of the year and '+ q1 + ' Monday of the month ' + mm);
      }else if(dayoftheweek==='Tuesday'){
          alert('This is ' + q + ' Tuesday of the year and '+ q1 + ' Tuesday of the month ' + mm);
      }else if(dayoftheweek==='Wednesday'){
          alert('This is ' + q + ' Wednesday of the year and  '+ q1 + ' Wednesday of the month ' +  mm);
      }else if(dayoftheweek==='Thursday'){
          alert('This is ' + q + ' Thursday of the year and '+ q1 + ' Thursday of the month ' + mm);
      }else{
          alert('Done!');
      }
      console.log(day);
  </code></pre>