title: jQuery cookie value as an AJAX response variable
body: <p>I have currency codes stored in a cookie. This values look like (EUR, USD, GBP, THB...)
  I do an AJAX request to a free API (exchangeratesapi.io), where I want to convert a certain amount of THB (Thai Baht), to any currency a user has set in his cookie.</p>
  
  <pre><code>    // Set currency cookie to GBP
      $.cookie("Currency", "GBP");
  
      // AJAX request to exchangeratesapi
      $.ajax({
          url: "https://api.exchangeratesapi.io/latest?base=THB",
          dataType: 'json'
      })
      .done(function(data) {
          // Set cookie value to var "tocur"
          var tocur = $.cookie("Currency");
          // Get exchange rate for GBP and store it in var "exchangerate" 
          var exchangerate = (data.rates.tocur);
          // Amount of THB to be exchanged to GBP
          var amount = 250;
          // Result for THB amount * exchangerate
          var sum = (amount * exchangerate);
          // Insert result into HTML element, roundet to 2 decimals, replace "." with ","
          $('#responsedata').html(amount + " THB = " + sum.toFixed(2).replace(".", ",") + " " + tocur);
      })
      .fail(function() {
          alert( "Could not fetch exchange rates" );
      });
  </code></pre>
  
  <p>This works fine, as long as I set the variable "exchangerate" manually to (data.rates.GBP). As soon as I try to set it to (data.rates.tocur), I get NaN as a result.</p>
  
  <p>Am I missing something? How can I get the cookie value stored in var "tocur" to work in my var exchangerate? Do I need to parse it somehow? Thank you very much in advance!</p>
  
  <p>I've put it in a JS-Fiddle also: <a href="https://jsfiddle.net/phii/72amuyLk/" rel="nofollow noreferrer">Here</a></p>