title: Condense an if statement to find what range a value fits in
body: <p>So I'm trying to make a compass app for the Fitbit Ionic, it works but this piece of code makes me angry. I know there's a way to condense it but I can't figure out how. It is supposed to take an integer and tell me what is the corresponding cardinal direction.</p>
  
  <p>It would look so much better if that if statement could be condensed. Any advice or solutions are greatly appreciated.</p>
  
  <pre><code>geolocation.watchPosition(function(position) {
  var headingDir;
  var headingDeg;
  headingDeg = position.coords.heading ? position.coords.heading.toFixed(2) : 0
  
  //This long boi
   if (headingDeg &gt;= 22.5 &amp; headingDeg &lt; 67.5) {
    headingDir = "NE";
   } else if (headingDeg &gt;= 67.5 &amp; headingDeg &lt; 112.5) {
    headingDir = "E"
   } else if (headingDeg &gt;= 112.5 &amp; headingDeg &lt; 157.5) {
    headingDir = "SE"
   } else if (headingDeg &gt;= 157.5 &amp; headingDeg &lt; 202.5) {
    headingDir = "S"
   } else if (headingDeg &gt;= 202.5 &amp; headingDeg &lt; 247.5) {
    headingDir = "SW"
   } else if (headingDeg &gt;= 247.5 &amp; headingDeg &lt; 292.5) {
    headingDir = "W"
   } else if (headingDeg &gt;= 292.5 &amp; headingDeg &lt; 337.5) {
    headingDir = "NW"
   } else {
    headingDir = "N"
   };
  
  })
  </code></pre>