hw09_06closure calc.html 896 B

1234567891011121314151617181920212223242526272829303132
  1. <head>
  2. <h1>closure calc</h1>
  3. </head>
  4. <body>
  5. <div id="rates">
  6. </div>
  7. <script>
  8. fetch(`https://open.er-api.com/v6/latest/USD`)
  9. .then(response => response.json())
  10. .then(data => {
  11. const name = 0;
  12. const value = 1;
  13. arr = Object.entries(data.rates);
  14. for (let i = 0; i < arr.length; i++) {
  15. let btn = document.createElement('button');
  16. btn.innerText = arr[i][name];
  17. let rateVal = arr[i][value];
  18. btn.onclick = () => {
  19. let amount = (+prompt("Enter amount") * rateVal);
  20. alert(amount);
  21. }
  22. rates.append(btn);
  23. rates.append(document.createElement("br"));
  24. }
  25. });
  26. </script>
  27. </body>