Skip to content

Instantly share code, notes, and snippets.

@yaroslavrick
Last active September 14, 2022 05:42
Show Gist options
  • Save yaroslavrick/a0185e355f01712e029582feed990153 to your computer and use it in GitHub Desktop.
Save yaroslavrick/a0185e355f01712e029582feed990153 to your computer and use it in GitHub Desktop.
Simple $ to BTC converter in JS by Yaroslav Yenkala
// Задача:
// - користувач вводить курс Bitcoin до доллара
// - користувач вводить суму доларів, що хоче поміняти на Bitcoin
// - програма повертає кількість Bitcoin, що можна купити на вказану суму.
// Приклад:
// What is Bitcoin price today?
// 21000
// How much $ do you have?
// 1000
// You can buy 0.0476190 BTC
// Gets user input
let price = prompt("What is Bitcoin price today?");
let wallet = prompt("How much $ do you have?");
function converterDolToCoin(price, wallet) {
if (!price || isNaN(price)) {
price = 21000;
}
if (!wallet) {
return alert(
"You need to go to Prog Academy, learn IT and you'll have some money",
);
}
const canBuy = wallet / price;
return canBuy.toFixed(7);
}
alert(`You can buy ${converterDolToCoin(price, wallet)} BTC`);
@yaroslavrick
Copy link
Author

Simple $ to BTC converter in JS by Yaroslav Yenkala
Specially for Prog Academy.
Yaroslav Yenkala

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment