title: how to wait for Http request complete?
body: <p>I write javascript app &quot;Blackjack&quot; and I need use some api.
  First I created a deck and request returns me deck id.</p>
  <pre class="lang-js prettyprint-override"><code>
              fetch('https://deckofcardsapi.com/api/deck/new/shuffle/?deck_count=1')
              .then(response =&gt; response.json())
              .then(data =&gt; {
                  console.log(data.deck_id);
                  deckId = data.deck_id;
              });
  </code></pre>
  <p>And then I want to draw cards.</p>
  <pre class="lang-js prettyprint-override"><code>           for(let i = 0; i &lt; 2; i++)
             {
                 for (let x = 0; x &lt; players.length; x++)
                  {
                      fetch('https://deckofcardsapi.com/api/deck/' + deckId + '/draw/?count=1')
                      .then(response =&gt; response.json())
                      .then(data =&gt; {
                          console.log(data.remaining);
                          deckLenght = data.remaining;
                          data.cards.map((card)=&gt;
                          {
                              var newCard = getCardData(card);
                              players[x].Hand.push(newCard);
                              renderCard(newCard, x);
                              updatePoints();
                              updateDeck();
                          });
                      });
                  }
              }
  </code></pre>
  <p>But when I send this request my deck id is undefined.
  How to fix that?</p>