-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
22 lines (20 loc) · 937 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const currencyOne = document.getElementById("currency-one");
const currencyTwo = document.getElementById("currency-two");
const getBtn = document.getElementById("convert-btn");
const Input = document.getElementById("amount")
const ansOne = document.getElementById("Ans-one");
const andTwo = document.getElementById("Ans-second");
function calculate() {
let currOne = currencyOne.value;
let currTwo = currencyTwo.value;
let input = Input.value;
//console.log(input);
fetch(` https://v6.exchangerate-api.com/v6/1e359e6846cdc9f51560acce/latest/${currOne}`)
.then(res => res.json())
.then(data => {
const rateAll = input * data.conversion_rates[currTwo];
const rate = data.conversion_rates[currTwo];
ansOne.innerText = `${input} ${currOne} = ${rateAll} ${currTwo}`;
andTwo.innerText = `1 ${currOne} = ${rate} ${currTwo}`;
})
}