Created
October 27, 2021 22:59
-
-
Save mrbusche/8d4077a20b008e787bdab512a615ec92 to your computer and use it in GitHub Desktop.
cryptos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
const cryptos = [ | |
{ type: 'SHIB', amount: 1311286.32422093 }, | |
]; | |
const formatter = new Intl.NumberFormat('en-US', { | |
style: 'currency', | |
currency: 'USD', | |
}); | |
function getTotals(cryptos) { | |
let total = 0; | |
cryptos.forEach((crypto) => | |
fetch(`https://min-api.cryptocompare.com/data/price?fsym=${crypto.type}&tsyms=USD`) | |
.then((response) => { | |
return response.json(); | |
}) | |
.then((data) => { | |
console.log([crypto.type, data.USD]); | |
const cryptoTotal = crypto.amount * data.USD; | |
total += cryptoTotal; | |
// console.log(['total from for loop', formatter.format(total)]); | |
console.log([`total for ${crypto.type}`, formatter.format(cryptoTotal)]); | |
return formatter.format(total); | |
}) | |
); | |
return total; | |
} | |
// const total = await getTotals(cryptos); | |
const total = getTotals(cryptos); | |
console.log(['total', total]); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment