I’m making a page that needs to have a Bitcoin quote.
On this page I need 2 inputs one that brings the price of bitcoin and another that brings the price in reais.
Ex: 1 Bitcoin costs xxx, xx (default value)
But when entering $ 100.00 in the real field he needs to bring the price equivalent to the amount of Bitcoins that is worth $ 100.00
The same for Bitcoin, if I enter a fraction it would need to bring the value in Reais.
I found a site that does this (
I got here, but it’s not doing like the site above.
HTML:
<body>
<div>
<input id=”currency” onBlur=”calcBitCoinValue()”/>
<input id=”bitcoin”/>
</div>
</body>
JAVASCRIPT:
let currentBitcoinValue = 0;
let currentCurrencyValue = 0;
function fetchBitcoinTickerJSON() {
const url = “
fetch(url)
.then(response => response.json())
.then(data => {
currentBitcoinValue = data.ticker.buy;
});
}
function init() {
fetchBitcoinTickerJSON();
}
function calcBitCoinValue() {
const bitCoin = document.getElementById(“bitcoin”);
const realValue = parseFloat(document.getElementById(“currency”).value);
bitCoin.value = realValue/currentBitcoinValue;
}
init();
Could they help?