1234567891011121314151617181920212223242526272829303132 |
- <head>
- <h1>closure calc</h1>
- </head>
- <body>
- <div id="rates">
- </div>
- <script>
- fetch(`https://open.er-api.com/v6/latest/USD`)
- .then(response => response.json())
- .then(data => {
- const name = 0;
- const value = 1;
- arr = Object.entries(data.rates);
- for (let i = 0; i < arr.length; i++) {
- let btn = document.createElement('button');
- btn.innerText = arr[i][name];
- let rateVal = arr[i][value];
- btn.onclick = () => {
- let amount = (+prompt("Enter amount") * rateVal);
- alert(amount);
- }
- rates.append(btn);
- rates.append(document.createElement("br"));
- }
- });
- </script>
- </body>
|