|
@@ -5,7 +5,6 @@
|
|
|
<title>convert</title>
|
|
|
</head>
|
|
|
<body>
|
|
|
-
|
|
|
<input type="input" name="convert" id="convert">
|
|
|
<p><b></b></p>
|
|
|
<div id="params">
|
|
@@ -15,180 +14,87 @@
|
|
|
<input type="checkbox" name="option4" value="a4" id="i4">CHF
|
|
|
<input type="checkbox" name="option5" value="a5" id='i5'>EUR
|
|
|
</div>
|
|
|
-
|
|
|
- <p><input type="button" name="btn" id="btn" value="Press" onclick="conv()"></p>
|
|
|
-
|
|
|
+ <p><input type="button" name="btn" id="btn" value="Convert" onclick="conv()"></p>
|
|
|
<div id="hid">
|
|
|
-
|
|
|
</div>
|
|
|
+ <script>
|
|
|
|
|
|
+ let uah=['USD','CNY','CHF','EUR'];
|
|
|
+ let usd=['UAH','CNY','CHF','EUR'];
|
|
|
+ let cny=['UAH','USD','CHF','EUR'];
|
|
|
+ let chf=['UAH','CNY','USD','EUR'];
|
|
|
+ let eur=['UAH','CNY','CHF','USD'];
|
|
|
|
|
|
- <script>
|
|
|
function conv(){
|
|
|
if(i1.checked==true){
|
|
|
while (hid.hasChildNodes()) {
|
|
|
hid.removeChild(hid.firstChild);
|
|
|
}
|
|
|
- fetch('https://open.er-api.com/v6/latest/UAH')
|
|
|
+ for(let i=0;i<uah.length;i++){
|
|
|
+ fetch('https://open.er-api.com/v6/latest/UAH')
|
|
|
.then(r=>r.json())
|
|
|
.then(data=>{
|
|
|
let p=document.createElement('p');
|
|
|
- p.innerHTML='USD: '+'$'+data.rates.USD*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/UAH')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='CNY: '+data.rates.CNY*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/UAH')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='CHF: '+data.rates.CHF*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/UAH')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
|
|
|
+ p.innerHTML=`${uah[i]}: `+(data.rates[uah[i]]*convert.value).toFixed(2);
|
|
|
hid.append(p);
|
|
|
});
|
|
|
+ }
|
|
|
}
|
|
|
if(i2.checked==true){
|
|
|
while (hid.hasChildNodes()) {
|
|
|
hid.removeChild(hid.firstChild);
|
|
|
}
|
|
|
- fetch('https://open.er-api.com/v6/latest/USD')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/USD')
|
|
|
+ for(let i=0;i<uah.length;i++){
|
|
|
+ fetch('https://open.er-api.com/v6/latest/USD')
|
|
|
.then(r=>r.json())
|
|
|
.then(data=>{
|
|
|
let p=document.createElement('p');
|
|
|
- p.innerHTML='CNY: '+data.rates.CNY*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/USD')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='CHF: '+data.rates.CHF*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/USD')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
|
|
|
+ p.innerHTML=`${usd[i]}: `+(data.rates[usd[i]]*convert.value).toFixed(2);
|
|
|
hid.append(p);
|
|
|
});
|
|
|
+ }
|
|
|
}
|
|
|
if(i3.checked==true){
|
|
|
while (hid.hasChildNodes()) {
|
|
|
hid.removeChild(hid.firstChild);
|
|
|
}
|
|
|
- fetch('https://open.er-api.com/v6/latest/CNY')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/CNY')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='USD: '+data.rates.USD*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/CNY')
|
|
|
+ for(let i=0;i<uah.length;i++){
|
|
|
+ fetch('https://open.er-api.com/v6/latest/CNY')
|
|
|
.then(r=>r.json())
|
|
|
.then(data=>{
|
|
|
let p=document.createElement('p');
|
|
|
- p.innerHTML='CHF: '+data.rates.CHF*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/CNY')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
|
|
|
+ p.innerHTML=`${cny[i]}: `+(data.rates[cny[i]]*convert.value).toFixed(2);
|
|
|
hid.append(p);
|
|
|
});
|
|
|
+ }
|
|
|
}
|
|
|
if(i4.checked==true){
|
|
|
while (hid.hasChildNodes()) {
|
|
|
hid.removeChild(hid.firstChild);
|
|
|
}
|
|
|
- fetch('https://open.er-api.com/v6/latest/CHF')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/CHF')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='CNY: '+data.rates.CNY*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/CHF')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='USD: '+data.rates.USD*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/CHF')
|
|
|
+ for(let i=0;i<uah.length;i++){
|
|
|
+ fetch('https://open.er-api.com/v6/latest/CHF')
|
|
|
.then(r=>r.json())
|
|
|
.then(data=>{
|
|
|
let p=document.createElement('p');
|
|
|
- p.innerHTML='EUR: '+Number(data.rates.EUR).toFixed(3)*convert.value;
|
|
|
+ p.innerHTML=`${chf[i]}: `+(data.rates[chf[i]]*convert.value).toFixed(2);
|
|
|
hid.append(p);
|
|
|
});
|
|
|
+ }
|
|
|
}
|
|
|
if(i5.checked==true){
|
|
|
while (hid.hasChildNodes()) {
|
|
|
hid.removeChild(hid.firstChild);
|
|
|
}
|
|
|
- fetch('https://open.er-api.com/v6/latest/EUR')
|
|
|
+ for(let i=0;i<uah.length;i++){
|
|
|
+ fetch('https://open.er-api.com/v6/latest/EUR')
|
|
|
.then(r=>r.json())
|
|
|
.then(data=>{
|
|
|
let p=document.createElement('p');
|
|
|
- p.innerHTML='UAH: '+'$'+data.rates.UAH*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/EUR')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='CNY: '+data.rates.CNY*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/EUR')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='CHF: '+data.rates.CHF*convert.value;
|
|
|
- hid.append(p);
|
|
|
- });
|
|
|
- fetch('https://open.er-api.com/v6/latest/EUR')
|
|
|
- .then(r=>r.json())
|
|
|
- .then(data=>{
|
|
|
- let p=document.createElement('p');
|
|
|
- p.innerHTML='USD: '+Number(data.rates.USD).toFixed(3)*convert.value;
|
|
|
+ p.innerHTML=`${eur[i]}: `+(data.rates[eur[i]]*convert.value).toFixed(2);
|
|
|
hid.append(p);
|
|
|
});
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|