title: Why does my variable turn to undefined all of sudden, when setting variable from parameter
body: <p>I am having problems with this code and can't figure out what is the problem. My idea is to first receive a parameter &quot;bet&quot; and check if the balance is enough, if it is user can start the game and play until he loses. Then when the player finally loses the server receives the &quot;score&quot; and the player is charged. The charging needs to happen after the score is set. But anyway the problem I have is that when the &quot;score&quot; is received and I try to access the recently set variable &quot;bet&quot; it 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>router.get('/:par',(req,res) =&gt;{
  
  const parameter = JSON.parse(req.params.par)
  const bet = parameter.bet
  
  
      if(parameter.bet != null){
          //check balance
          console.log(bet)
  
          res.send("StartTheGame")
      }
      else if(parameter.Score != null){
      console.log(bet)
      //returns undefined?
      }
  
  })</code></pre>
  </div>
  </div>
  </p>
  <p>My guess is that when the Score is sent, there is no bet parameter and it sets it to undefined but  I don't know how to fix it. Also new to javascript so forgive me if this is not the way to do this.</p>