123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>convert</title>
- </head>
- <body>
- <input type="input" name="convert" id="convert">
- <p><b></b></p>
- <div id="params">
- <input type="checkbox" name="option1" value="a1" id="i1">UAH
- <input type="checkbox" name="option2" value="a2" id="i2">USD
- <input type="checkbox" name="option3" value="a3" id="i3">CNY
- <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="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'];
- function conv(){
- if(i1.checked==true){
- while (hid.hasChildNodes()) {
- hid.removeChild(hid.firstChild);
- }
- 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=`${uah[i]}: `+(data.rates[uah[i]]*convert.value).toFixed(2);
- hid.append(p);
- });
- }
- }
- if(i2.checked==true){
- while (hid.hasChildNodes()) {
- hid.removeChild(hid.firstChild);
- }
- 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=`${usd[i]}: `+(data.rates[usd[i]]*convert.value).toFixed(2);
- hid.append(p);
- });
- }
- }
- if(i3.checked==true){
- while (hid.hasChildNodes()) {
- hid.removeChild(hid.firstChild);
- }
- 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=`${cny[i]}: `+(data.rates[cny[i]]*convert.value).toFixed(2);
- hid.append(p);
- });
- }
- }
- if(i4.checked==true){
- while (hid.hasChildNodes()) {
- hid.removeChild(hid.firstChild);
- }
- 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=`${chf[i]}: `+(data.rates[chf[i]]*convert.value).toFixed(2);
- hid.append(p);
- });
- }
- }
- if(i5.checked==true){
- while (hid.hasChildNodes()) {
- hid.removeChild(hid.firstChild);
- }
- 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=`${eur[i]}: `+(data.rates[eur[i]]*convert.value).toFixed(2);
- hid.append(p);
- });
- }
- }
- }
- //let urls=['UAH','USD','CNY','CHF','EUR'];
- </script>
- </body>
- </html>
|