title: How do I return the day of the week with a function?
body: <p>Edit:</p>
  <p>The suggestions in the comments worked. But how do I return &quot;null&quot; if parameter is outside a given range like 1-7? Edited code below.</p>
  <p>Code needs to return the day of the week when called. For example.
  returnDay(1) //&quot;Monday&quot;
  returnDay(2) //&quot;Tuesday&quot;
  etc...</p>
  <p>My code:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function returnDay(day) {
      var dayOfWeek = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday');
      for (var i = 0; i &lt; day.length; i++) {
          dayOfWeek += day[i];
      }
      return dayOfWeek;
  }
  
  console.log(returnDay(1)) //returns full array, not 'Monday'</code></pre>
  </div>
  </div>
  </p>
  <p>New code with new problems :( returns undefined</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function returnDay(day) {
      var dayOfWeek = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
      if (returnDay &lt;= 0 &amp;&amp; returnDay &gt;= 8) {
          return null;
      } else {
          return dayOfWeek[day - 1];
      }
  }
  console.log(returnDay(0)); //returns undefined</code></pre>
  </div>
  </div>
  </p>