I would like to thank you for any help you can offer.
With all of the cryptocurrency craze I wanted to make a USD to DOGE converter for a website I had in mind. This is my first time using jQuery.
The script converts $11 USD (price of service I want to offer) and converts it to Bitcoin. It then converts Bitcoin ($11 USD worth) to Dogecoin.
The problem is, about half of the time, the number that the script returns and adds to the "price" h1 text is 0. How can I give the JSON parse more time so that the script doesn't show 0 as the amount? Or is there another problem I am unaware of?
var $BTCUSD = '';
var $BTC = '';
var $DOGEBTC = '';
var $DOGE = '';
var $price = '';
$.getJSON('http://www.cryptocoincharts.info/v2/api/tradingPair/btc_usd', function(btc) {
$BTCUSD = btc.price;
$BTC = 11 / $BTCUSD;
});
$.getJSON('http://www.cryptocoincharts.info/v2/api/tradingPair/doge_btc', function(doge) {
$DOGEBTC = doge.price;
$DOGE = $BTC / $DOGEBTC;
$price = parseFloat($DOGE.toPrecision(2));
// output
document.getElementById('price').innerHTML = $price;
});