Created
June 22, 2022 02:03
-
-
Save ashraf267/608687a1cdae5cc93da18c0758d37111 to your computer and use it in GitHub Desktop.
sample code for my first hyperskill x jetbrains project
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
| console.log("Welcome to Currency Converter!"); | |
| console.log(`1 USD equals 1 USD | |
| 1 USD equals 113.5 JPY | |
| 1 USD equals 0.89 EUR | |
| 1 USD equals 74.36 RUB | |
| 1 USD equals 0.75 GBP`); | |
| console.log("I can convert USD to these currencies: JPY, EUR, RUB, USD, GBP"); | |
| console.log("Type the currency you wish to convert: USD"); | |
| // currency? | |
| let curr = "JPY"; | |
| console.log("To: " + curr); | |
| // amount? | |
| let amnt = 53; | |
| console.log("Amount: " + amnt); | |
| // convert currency | |
| function convCurr(currency, amount) { | |
| let output; | |
| // check if amount is < 1 and if amount != a number | |
| function checks(currVal) { | |
| if(amount < 1) { | |
| output = "The amount cannot be less than 1"; | |
| } else if(isNaN(amount)) { | |
| output = "The amount has to be a number"; | |
| } else { | |
| output = amount * currVal; | |
| } | |
| } | |
| // check all currencies for a match | |
| if(currency == "JPY" || currency == "jpy") { | |
| checks(113.5); | |
| } else if(currency == "EUR" || currency == "eur") { | |
| checks(0.89); | |
| } else if(currency == "RUB" || currency == "rub") { | |
| checks(74.36); | |
| } else if(currency == "GBP" || currency == "gbp") { | |
| checks(0.75); | |
| } else if(currency == "USD" || currency == "usd") { | |
| checks(1); | |
| } else { | |
| output = "Unknown currency"; | |
| } | |
| // return output | |
| return output; | |
| } | |
| // call function and store output in result | |
| let result = convCurr(curr, amnt); | |
| isNaN(result) ? console.log(result) : console.log(amnt + " USD equals " + result + " " + curr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment