11_currency_calc_improved.js 643 B

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