makstravm пре 3 година
комит
dc941e2921
4 измењених фајлова са 171 додато и 0 уклоњено
  1. 31 0
      HW1/index.html
  2. 44 0
      HW1/main.js
  3. 49 0
      HW1/reset.css
  4. 47 0
      HW1/style.css

+ 31 - 0
HW1/index.html

@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html lang="en-ru">
+
+<head>
+  <meta charset="UTF-8">
+  <meta http-equiv="X-UA-Compatible" content="IE=edge">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <title>Обмен валют</title>
+  <link rel="stylesheet" href="reset.css">
+  <link rel="stylesheet" href="style.css">
+</head>
+
+<body>.
+  <div class="wrapper">
+    <h1 class="title">Обмен валют</h1>
+    <h2 class='today'> Последнее обновление <span class="today__text" id="todayDate"></span></h2>
+    <div class="price">
+      <div class="price__inner">
+        <input id="numberOne" type="number" class="price__number" value="0" min="0">
+        <select id="currencyOne" class="currency"></select>
+      </div>
+      <div class="price__inner">
+        <input id="numberTwo" type="number" class="price__result" value="0" disabled>
+        <select id="currencyTwo" class="currency"></select>
+      </div>
+    </div>
+  </div>
+  <script src="main.js"></script>
+</body>
+
+</html>

+ 44 - 0
HW1/main.js

@@ -0,0 +1,44 @@
+fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json())
+  .then(data => {
+    const currencyArray = Object.keys(data.rates)
+    const currencyObj = data.rates;
+    const updateDateTime = data.time_last_update_utc
+    const selectCurrency = document.querySelectorAll('select.currency')
+    const currencyOne = document.getElementById('currencyOne')
+    const currencyTwo = document.getElementById('currencyTwo')
+    const numberOne = document.getElementById('numberOne')
+    const numberTwo = document.getElementById('numberTwo')
+    const todayDate = document.getElementById('todayDate')
+
+    todayDate.innerText = `${updateDateTime.slice(0, 16)}`
+
+    for (let i = 0; i < selectCurrency.length; i++) {
+      currencyArray.map(c => {
+        let option = document.createElement("option")
+        option.setAttribute('value', c)
+        option.text = `${c}`
+        selectCurrency[i].appendChild(option)
+      })
+    }
+
+    const calcCurrency = () => {
+      if (currencyOne.value === currencyTwo.value) {
+        numberTwo.value = numberOne.value
+      } else {
+        let result = numberOne.value / currencyObj[currencyOne.value] * currencyObj[currencyTwo.value]
+        numberTwo.value = result.toFixed(3)
+      }
+    }
+
+    currencyOne.addEventListener("change", function () {
+      calcCurrency()
+    })
+
+    currencyTwo.addEventListener("change", function () {
+      calcCurrency()
+    })
+
+    numberOne.addEventListener("change", function () {
+      calcCurrency()
+    })
+  })

+ 49 - 0
HW1/reset.css

@@ -0,0 +1,49 @@
+html{
+  box-sizing: border-box;
+}
+
+*,
+*::after,
+*::before{
+  box-sizing: inherit;
+}
+
+ul[class],
+ol[class] {
+  padding: 0;
+}
+
+body,
+h1,
+h2,
+h3,
+h4,
+h5,
+h6,
+p,
+ul[class],
+ol[class],
+li,
+figure,
+figcaption,
+blockquote,
+dl,
+dd {
+  margin: 0;
+}
+
+ul[class] {
+  list-style: none;
+}
+
+img {
+  max-width: 100%;
+  display: block;
+}
+
+input,
+button,
+textarea,
+select {
+  font: inherit;
+}

+ 47 - 0
HW1/style.css

@@ -0,0 +1,47 @@
+body {
+  font-size: 14px;
+  line-height: 20px;
+  background-color: #ececec;
+  color: #000;
+  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
+}
+.wrapper {
+  padding: 7% 3%;
+}
+.title {
+  text-align: center;
+  font-size: 2.2em;
+  line-height: 2em;
+}
+.today {
+  text-align: center;
+  margin-bottom: 1%;
+  font-size: 1.8em;
+  line-height: 1.8em;
+}
+.price__inner {
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  padding-bottom: 2%;
+}
+.price__number,
+.currency {
+  width: 150px;
+  padding: 5px;
+  text-align: center;
+  color: #000000;
+  background-color: transparent;
+}
+.currency {
+  width: 100px;
+  margin-left: 15px;
+}
+.price__result {
+  width:150px;
+  background-color: transparent;
+  text-align: center;
+  color: #ff0000;
+  font-size: 1.5em;
+  font-weight: bold;
+}