title: Why can't i map a range of number to another range of number in Javascript?
body: <p>I'm making this blurry effect so that my percentage will go blurrier as it gets to 100%. However, it doesn't work...the console says &quot;Cannot access '<em>scale' before initialization
  at blurring</em> &quot; which is in line 16 of my script.js.
  Anybody knows what is wrong please help me! Thank you so much!</p>
  <p>This is 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>const loadText = document.querySelector('.loading-text')
  const bg = document.querySelector('.bg')
  let load = 0
  let int = setInterval(blurring, 30)
  
  function blurring() {
    load++
  
    if (load &gt; 99) {
      clearInterval(int)
    }
  
    loadText.innerText = `${load}%`
    loadText.style.opacity = scale(load, 0, 100, 1, 0)
  
    const scale = (num, in_min, in_max, out_min, out_max) =&gt; {
      return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min
    }
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>* {
    box-sizing: border-box;
  }
  
  body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
    margin: 0;
  }
  
  .bg {
    background: url('z.jpg') no-repeat center center/cover;
    position: absolute;
    top: -30px;
    left: -30px;
    width: calc(100vw + 60px);
    height: calc(100vw + 60px);
    z-index: -1;
    filter: blur(0px)
  }
  
  .loading-text {
    padding: 50% 50%;
    font-size: 50px;
    color: #fff;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  
  &lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
    &lt;title&gt;Blurry Loading&lt;/title&gt;
    &lt;link rel="stylesheet" href="style.css"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;section class="bg"&gt;
      &lt;div class="loading-text"&gt;
        0%
      &lt;/div&gt;
    &lt;/section&gt;
  
    &lt;script src="script.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>