script.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const wrapper = document.querySelector('.cur__wrapper');
  2. function exchange(currency) {
  3. let url = 'https://open.er-api.com/v6/latest/' + currency.toUpperCase();
  4. if (currency.toLowerCase() === 'usd' || currency.toLowerCase() === 'eur' || currency.toLowerCase() === 'rub') {
  5. fetch(url)
  6. .then(res => res.json())
  7. .then(data => {
  8. let sum = prompt('enter amount');
  9. alert(`You usd summ : ${sum * data.rates.UAH} uah`);
  10. });
  11. } else if (currency) {
  12. fetch(url)
  13. .then(res => res.json())
  14. .then(data => {
  15. let sum = prompt('enter amount');
  16. alert(`You usd summ : ${sum * data.rates.UAH} uah`);
  17. });
  18. } else {
  19. alert('Enter correct currency name');
  20. }
  21. };
  22. function showCurencys() {
  23. fetch('https://open.er-api.com/v6/latest').then(res => res.json())
  24. .then(data => {
  25. for (let key in data.rates) {
  26. let div = document.createElement('div');
  27. wrapper.appendChild(div);
  28. div.innerHTML =`<button class='btn_cur'> ${key}</button>`;
  29. }
  30. exchange();
  31. });
  32. }
  33. showCurencys();