1234567891011121314151617181920212223242526272829303132333435 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <select name="" id="rates" value = ""></select>
- <input type="number" id="amount">
- <h1 id = "result" value = ""></h1>
- <script>
- fetch('https://api.exchangeratesapi.io/latest')
- .then(res => res.json())
- .then(d => {
- console.log(d) // тут у нас есть данные
- //и ниже с ними можно работать
- //нигде кроме этой функции (этих фигурных скобок) переменной d нет
- let str = ''
- for (let currency in d.rates) {
- console.log(currency, d.rates[currency])
- str += `<option value="${d.rates[currency]}">:${currency}</option>`
- }
- rates.innerHTML = str
- })
- console.log(amount.value, rates.value)
- amount.oninput = () => {
- let text = ""
- text = text + (amount.value*rates.value)
- result.innerHTML = text
- }
- </script>
- </body>
- </html>
|