From fe77a1cee053fc32a2f2ff4c8e2fba1ff28e3107 Mon Sep 17 00:00:00 2001 From: Xaloc Date: Mon, 22 Jun 2020 00:58:58 +0200 Subject: [PATCH] add reverse conversion --- index.html | 38 ++++++++++++++++++++++++++++++++++++-- script.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index 54293ad..7e75811 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,8 @@ - @@ -22,7 +23,7 @@ - @@ -40,7 +41,40 @@

Conversion:

+

Reversed conversion

+From: + + +To: + + + +

+Conversion: +

diff --git a/script.js b/script.js index af29a92..886f341 100644 --- a/script.js +++ b/script.js @@ -15,3 +15,38 @@ async function convert(){ var val = document.getElementById('val').value; document.getElementById('res').textContent = Number((val*coef).toFixed(2)).toLocaleString('en') + ' ' +document.getElementById('curr2').value; } + +async function convert2(){ + const base = document.getElementById('rev').value; + const rates = await api(base); + const cur = document.getElementById('rev2').value; + var coef = rates[cur]; + if (base==cur){ + coef = 1; + } + var val = document.getElementById('val2').value; + document.getElementById('res2').textContent = Number((val*coef).toFixed(2)).toLocaleString('en') + ' ' +document.getElementById('rev2').value; +} + +const from1 = document.getElementById('curr'); +const to1 = document.getElementById('curr2'); + +const from2 = document.getElementById('rev'); +const to2 = document.getElementById('rev2'); + +from1.onchange = function(a){ + to2.value = a.target.value; +}; + +to1.onchange = function(a){ + from2.value = a.target.value; +}; + +from2.onchange = function(a){ + to1.value = a.target.value; +}; + +to2.onchange = function(a){ + from1.value = a.target.value; +}; +