15_currency_calc_object.js 685 B

123456789101112131415161718192021222324252627
  1. let currency = prompt('Укажите валюту:');
  2. let exchangeRate = null;
  3. let exchangeRateSymbol = '';
  4. let ratios = {
  5. usd: 39.15,
  6. eur: 39.55
  7. }
  8. switch (currency) {
  9. case 'usd':
  10. exchangeRate = ratios.usd;
  11. exchangeRateSymbol = '$';
  12. break;
  13. case 'eur':
  14. exchangeRate = ratios.eur;
  15. exchangeRateSymbol = '€';
  16. break;
  17. default:
  18. alert('Неверно указанная валюта');
  19. }
  20. if(currency === 'usd' || currency === 'eur' ) {
  21. let quantity = +prompt('Укажите величину в гривне для обмена');
  22. alert(`${quantity} грн в ${currency} = ${(quantity / exchangeRate).toFixed(2)}${exchangeRateSymbol}`);
  23. }