Link, który użyłeś w linii 7
axios.get("https://api.exchangerate.host/convert?from=" + amount1 +"&to" + amount2)
zwraca obiekt typu json
https://api.exchangerate.host/convert?from=USD&toUSD
{"motd":{"msg":"If you or your company use this project or like what we doing, please consider backing us so we can continue maintaining and evolving this project.","url":"https://exchangerate.host/#/donate"},"success":true,"query":{"from":"USD","to":"","amount":1},"info":{"rate":null},"historical":false,"date":"2022-06-30","result":null}
no i "zgubiłeś" znak = w linku
https://api.exchangerate.host/convert?from=USD&to=USD
{"motd":{"msg":"If you or your company use this project or like what we doing, please consider backing us so we can continue maintaining and evolving this project.","url":"https://exchangerate.host/#/donate"},"success":true,"query":{"from":"USD","to":"USD","amount":1},"info":{"rate":1},"historical":false,"date":"2022-06-30","result":1}
wygląda na to, że chodzi o pola
response.data.result;
lub
response.data.info.rate;
sprawdź tak:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<h2 class="text-center pb-3">
Kursy walut
</h2>
<h3 class="text-center pb-3">
Wybierz pierwszą walutę
</h3>
<select id="amount1">
<option value="USD">Dolar amerykanski</option>
<option value="EUR">Euro</option>
<option value="PLN">Polski zloty</option>
</select>
<h3 class="text-center pb-3">
Wybierz drugą walutę walutę
</h3>
<select id="amount2">
<option value="USD">Dolar amerykanski</option>
<option value="EUR">Euro</option>
<option value="PLN">Polski zloty</option>
</select>
<h3 class="text-center pb-3">
-----------------------
</h3>
<button onclick="getResult()">Pobierz dane</button>
<h3 class="text-center pb-3">
Oto kurs:
</h3>
<pre id="result"></pre>
<script>
function getResult() {
const amount1 = document.getElementById("amount1").value,
amount2 = document.getElementById("amount2").value;
axios.get("https://api.exchangerate.host/convert?from=" + amount1 +"&to=" + amount2)
.then(response => {
console.log(response.data);
document.getElementById("result").textContent = (JSON.stringify(response.data)).replaceAll(',', ',\n');
document.getElementById("result").textContent += '\n\n' + response.data.result;
document.getElementById("result").textContent += '\n' + response.data.info.rate;
});
}
</script>