Skip to content

Instantly share code, notes, and snippets.

@cargabsj175
Forked from ivorpad/dolarparalelo.js
Created January 31, 2018 03:11
Show Gist options
  • Save cargabsj175/57603dafc5d5d469e7b4916718e9275c to your computer and use it in GitHub Desktop.
Save cargabsj175/57603dafc5d5d469e7b4916718e9275c to your computer and use it in GitHub Desktop.
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