JavaScript for getting the previous Monday
<p>I would like for the previous Monday to appear in the field where a user enters today's date.</p>
<p><strong>E.g.:</strong> If today's date is entered <code>29-Jan-16</code> then the code would make the previous Monday's date to appear instead (which would be <code>25-Jan-16</code>).</p>
<p>I have seen some code online:</p>
<pre><code>function getPreviousMonday() {
  var date = new Date();
  if (date.getDay() != 0) {
    return new Date().setDate(date.getDate() - 7 - 6);
  } else {
    return new Date().setDate(date.getDate() - date.getDate() - 6);
  }
}
</code></pre>
<p>However, this is not quite working, why?</p>