Last active
September 14, 2022 05:42
-
-
Save yaroslavrick/a0185e355f01712e029582feed990153 to your computer and use it in GitHub Desktop.
Simple $ to BTC converter in JS by Yaroslav Yenkala
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
// Задача: | |
// - користувач вводить курс 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`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple $ to BTC converter in JS by Yaroslav Yenkala
Specially for Prog Academy.
Yaroslav Yenkala