-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
24 lines (19 loc) · 842 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const amountInput = document.querySelector("#amount");
const firstOption = document.querySelector("#firstCurrencyOption");
const secondOption = document.querySelector("#secondCurrencyOption");
const resultInput = document.querySelector("#result");
const button = document.querySelector("#button");
runEventListener();
const currency = new Currency();
function runEventListener(){
button.addEventListener("click", exchange);
}
function exchange(){
const amount = Number(amountInput.value.trim());
const firstOptionValue = firstOption.options[firstOption.selectedIndex].textContent;
const secondOptionValue = secondOption.options[secondOption.selectedIndex].textContent;
currency.exchangeCurrency(amount, firstOptionValue, secondOptionValue)
.then((result)=>{
resultInput.value = result.toFixed(1);
})
}