title: JS Switch calculator number limiter
body: <p>I need to limit the max and min output value for the calculator. I tried multiple ways, always an error. Then I tried this one, declaring result variable so I can catch it and set if statement for my limiter, no error this time, but it doesn't work.</p>
  <pre><code>let calc = function (operator, a, b = undefined) {
      let result
      if(result &gt; 9999 || result &lt; -9999) {
      console.log('Digit limit')
  }
      switch (operator) {
       
          case '+':
              result = a + b;
              return result
          case '-':
              result = a - b;
              return result
          case '*':
              result = a * b;
              return result
          case '/':
              if (a === 0 || b === 0) {
                  alert('Invalid operation');
              }
              result = a / b;
              return result
          case 'pow':
              result = Math.pow(a, b);
              return result
  
          case 'log':
              if (a &lt;= 0) {
                  return NaN
              }
              result = Math.log(a);
              return result
          case 'sqrt':
              if (a &lt;= 0) {
                  return NaN
              }
              result = Math.sqrt(a);
              return result
      }
    
  }
  
  </code></pre>