-
-
Save cargabsj175/57603dafc5d5d469e7b4916718e9275c to your computer and use it in GitHub Desktop.
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
const getBsfOfParalelo = (ticker, quantity, discount = 0) => { | |
ticker = ticker.toUpperCase(); | |
return fetch("https://s3.amazonaws.com/dolartoday/data.json") | |
.then(res => res.json()) | |
.catch((err) => { throw new Error('Data cannot be reached. Check the URL.') }) | |
.then(val => { | |
let price = val[ticker].dolartoday; | |
let results = | |
discount > 0 ? (price - discount) * quantity : price * quantity; | |
return results.toLocaleString('es-ve', { | |
style: 'currency', | |
currency: 'BSF', | |
}); | |
}); | |
}; | |
// ticker: usd | eur | |
// discount: in bsf —> normally between 2000 & 4000 | |
getBsfOfParalelo("usd", 300, 2000).then(val => console.log(val)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment