瀏覽代碼

HW6 without belts done

maryluis 4 年之前
父節點
當前提交
9e8ece9899
共有 3 個文件被更改,包括 188 次插入0 次删除
  1. 11 0
      homework6js/1/exersices.html
  2. 142 0
      homework6js/1/script.js
  3. 35 0
      homework6js/calc.html

+ 11 - 0
homework6js/1/exersices.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script src="./script.js"></script>
+</body>
+</html>

+ 142 - 0
homework6js/1/script.js

@@ -0,0 +1,142 @@
+
+let mas = []
+let a = {
+    name: "Misha",
+    surname: "Muslim"
+}
+a.fathername = "Svinonich"
+a.age = "24"
+a.country = "Ukraine"
+a.sex = "male"
+a.marriage = true;
+let b = {
+    name: "Oleh",
+    surname: "Glamazda",
+}
+
+b.age = "25"
+b.country = "Ukraine"
+b.marriage = false
+let c = {
+    name: "Katya",
+    surname: "Krasnoshok",
+}
+c.age = "30"
+c.sex = "female"
+let persons = []
+persons.push(a, b, c)
+function fieldsCheck(check) {
+    for(let i = 0; i < persons.length; i++) {
+        let str = ""
+        check = persons[i]
+        for(let key in check){
+            (key == "name" || key == "surname" ) ? str += ""
+            : str += key + " "
+        }
+        if(str == "") {
+            alert("Nothing in " + check.name)
+        } else {
+            alert(str + " in " + check.name)
+        }
+    }
+}
+// fieldsCheck()
+persons.push({name: "Tom",
+            surname: "Motgan",
+            country: "UK",
+            marriage: true         
+})
+function personsObj(obj) {
+    for (let i = 0; i < obj.length; i++){
+        console.log(obj[i])
+    }
+}
+// personsObj(persons)
+function personsNamSurn(obj) {
+    for(let i = 0; i < obj.length; i++) {
+        console.log(obj[i].name + " " + obj[i].surname)
+    }
+}
+// personsNamSurn(persons)
+function personsValues(obj) {
+    let cons = "";
+    for(let i = 0; i < obj.length; i++) {
+        let check = obj[i]
+        for (let key in check) {
+            cons += check[key] + " "
+        }
+        cons += "\n"
+    }
+    console.log(cons)
+}
+// personsValues(persons)
+
+function fullName(obj) {
+    for(let i = 0; i < obj.length; i++) {
+        let value = "";
+        let check = obj[i]
+        for(let key in check) {
+            if(key == "name" || key == "fathername" || key == "surname"){
+                value += check[key] + " "
+            }
+        }
+        check.fullName = value
+    }
+}
+// fullName(persons)
+var json = (JSON.stringify(persons, null, " "))
+
+// console.log(json)
+var e = JSON.parse('{"name":"Petr","surname":"Vlasenco","fathername":"Andreevich","age":"40","country":"Belarus","marriage":"true"}')
+persons.push(e)
+
+function toHtmlTable(obj) {
+    var str = "<table border='1'>"
+    for (let i=0;i<obj.length;i++){
+        let check = obj[i]
+        str += `<tr><td>${i}</td>`
+        for (let key in check){
+            str += `<td>${check[key]}</td>`
+        }
+        str += `</tr>`
+    }
+    str += "</table>"
+
+    document.write(str)
+}
+// toHtmlTable(persons)
+
+function htmlOptional(obj) {
+    debugger
+    let str = `<table border='1'><tr><td style = "background-color: yellow"></td>`
+    let valueMas =[]
+    for (let i=0;i<obj.length;i++){
+        let check = obj[i]
+        for(let key in check) {
+            if(str.includes(key)){
+            } else{
+            str +=`<th  style = "background-color: yellow">${key}</th>`
+            valueMas.push(key)
+            }
+        }
+    }
+    for (let j=0;j<obj.length;j++){
+        let check = obj[j]
+        str += `<tr><td style = "background-color: yellow">${j}</td>`
+        let keysArr = Object.keys(check);
+        for(let k = 0; k < valueMas.length; k++) {
+            if(keysArr.indexOf(valueMas[k]) == -1) {
+               str += `<td style = "background-color: red"></td>`
+            } else {
+               str += `<td style = "background-color: #89e0c0">${check[valueMas[k]]}</td>`
+            }
+        }
+        str += `</tr>`
+    }
+    str += "</table>"
+
+    console.log(str)
+    document.write(str)
+}
+htmlOptional(persons)
+

+ 35 - 0
homework6js/calc.html

@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <select name="" id="rates" value = ""></select>
+    <input type="number" id="amount">
+    <h1 id = "result" value = ""></h1>
+    <script>
+        fetch('https://api.exchangeratesapi.io/latest')
+        .then(res => res.json())
+        .then(d => {
+        console.log(d) // тут у нас есть данные
+        //и ниже с ними можно работать
+        //нигде кроме этой функции (этих фигурных скобок) переменной d нет
+        let str = ''
+        for (let currency in d.rates) {
+
+            console.log(currency, d.rates[currency])
+            str += `<option value="${d.rates[currency]}">:${currency}</option>`
+        }
+        rates.innerHTML = str
+    })
+    console.log(amount.value, rates.value)
+        amount.oninput = () => {
+            let text = ""
+            text = text + (amount.value*rates.value)
+            result.innerHTML = text
+        }
+    </script>
+</body>
+</html>