convertValuti.html 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>convert</title>
  6. </head>
  7. <body>
  8. <input type="input" name="convert" id="convert">
  9. <p><b></b></p>
  10. <div id="params">
  11. <input type="checkbox" name="option1" value="a1" id="i1">UAH
  12. <input type="checkbox" name="option2" value="a2" id="i2">USD
  13. <input type="checkbox" name="option3" value="a3" id="i3">CNY
  14. <input type="checkbox" name="option4" value="a4" id="i4">CHF
  15. <input type="checkbox" name="option5" value="a5" id='i5'>EUR
  16. </div>
  17. <p><input type="button" name="btn" id="btn" value="Convert" onclick="conv()"></p>
  18. <div id="hid">
  19. </div>
  20. <script>
  21. let uah=['USD','CNY','CHF','EUR'];
  22. let usd=['UAH','CNY','CHF','EUR'];
  23. let cny=['UAH','USD','CHF','EUR'];
  24. let chf=['UAH','CNY','USD','EUR'];
  25. let eur=['UAH','CNY','CHF','USD'];
  26. function conv(){
  27. if(i1.checked==true){
  28. while (hid.hasChildNodes()) {
  29. hid.removeChild(hid.firstChild);
  30. }
  31. for(let i=0;i<uah.length;i++){
  32. fetch('https://open.er-api.com/v6/latest/UAH')
  33. .then(r=>r.json())
  34. .then(data=>{
  35. let p=document.createElement('p');
  36. p.innerHTML=`${uah[i]}: `+(data.rates[uah[i]]*convert.value).toFixed(2);
  37. hid.append(p);
  38. });
  39. }
  40. }
  41. if(i2.checked==true){
  42. while (hid.hasChildNodes()) {
  43. hid.removeChild(hid.firstChild);
  44. }
  45. for(let i=0;i<uah.length;i++){
  46. fetch('https://open.er-api.com/v6/latest/USD')
  47. .then(r=>r.json())
  48. .then(data=>{
  49. let p=document.createElement('p');
  50. p.innerHTML=`${usd[i]}: `+(data.rates[usd[i]]*convert.value).toFixed(2);
  51. hid.append(p);
  52. });
  53. }
  54. }
  55. if(i3.checked==true){
  56. while (hid.hasChildNodes()) {
  57. hid.removeChild(hid.firstChild);
  58. }
  59. for(let i=0;i<uah.length;i++){
  60. fetch('https://open.er-api.com/v6/latest/CNY')
  61. .then(r=>r.json())
  62. .then(data=>{
  63. let p=document.createElement('p');
  64. p.innerHTML=`${cny[i]}: `+(data.rates[cny[i]]*convert.value).toFixed(2);
  65. hid.append(p);
  66. });
  67. }
  68. }
  69. if(i4.checked==true){
  70. while (hid.hasChildNodes()) {
  71. hid.removeChild(hid.firstChild);
  72. }
  73. for(let i=0;i<uah.length;i++){
  74. fetch('https://open.er-api.com/v6/latest/CHF')
  75. .then(r=>r.json())
  76. .then(data=>{
  77. let p=document.createElement('p');
  78. p.innerHTML=`${chf[i]}: `+(data.rates[chf[i]]*convert.value).toFixed(2);
  79. hid.append(p);
  80. });
  81. }
  82. }
  83. if(i5.checked==true){
  84. while (hid.hasChildNodes()) {
  85. hid.removeChild(hid.firstChild);
  86. }
  87. for(let i=0;i<uah.length;i++){
  88. fetch('https://open.er-api.com/v6/latest/EUR')
  89. .then(r=>r.json())
  90. .then(data=>{
  91. let p=document.createElement('p');
  92. p.innerHTML=`${eur[i]}: `+(data.rates[eur[i]]*convert.value).toFixed(2);
  93. hid.append(p);
  94. });
  95. }
  96. }
  97. }
  98. //let urls=['UAH','USD','CNY','CHF','EUR'];
  99. </script>
  100. </body>
  101. </html>