Last active
January 31, 2018 03:11
-
-
Save ivorpad/d156c1ec1d6a3d966fd5c00f5afb9888 to your computer and use it in GitHub Desktop.
This file contains hidden or 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