소스 검색

HW<5> done

Andrey 2 년 전
부모
커밋
ac5376d419
1개의 변경된 파일330개의 추가작업 그리고 0개의 파일을 삭제
  1. 330 0
      Dz5 js/Dz5js.html

+ 330 - 0
Dz5 js/Dz5js.html

@@ -0,0 +1,330 @@
+<!DOCTYPE html>
+<html lang="en">
+
+<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>Document</title>
+</head>
+
+<body>
+    <script>
+        // 3 persons
+        let a = {
+            name: "Andrey",
+            surname: "Ivanov",
+        }
+        let b = {
+            name: "Igor",
+            surname: "Vasin",
+        }
+        let c = {
+            name: "Oleg",
+            surname: "Petrov",
+        }
+
+
+        //different fields
+        let a = {
+            name: "Andrey",
+            surname: "Ivanov",
+            fathername: "Andreevich",
+            age: 21,
+            sex: "male"
+        }
+        let b = {
+            name: "Igor",
+            surname: "Vasin",
+            fathername: "Igorevich",
+            age: 31
+        }
+        let c = {
+            name: "Oleg",
+            surname: "Petrov",
+            fathername: "Olegovich"
+        }
+
+        //fields check
+        let a = {
+            name: "Andrey",
+            surname: "Ivanov",
+            fathername: "Andreevich",
+            age: 21,
+            sex: "male"
+        }
+        let b = {
+            name: "Igor",
+            surname: "Vasin",
+            fathername: "Igorevich",
+            age: 31
+        }
+        let c = {
+            name: "Oleg",
+            surname: "Petrov",
+            fathername: "Olegovich"
+        }
+        if ("sex" in a) {
+            alert(a.sex)
+        } if ("age" in a) {
+            alert(a.age)
+        } if ("sex" in b) {
+            alert(b.sex)
+        } if ("age" in b) {
+            alert(b.age)
+        } if ("sex" in c) {
+            alert(c.sex)
+        } if ("age" in c) {
+            alert(c.age)
+        }
+
+        //array of persons
+        let arraypersons = [a, b, c, { name: 'Daniil', surname: 'Kovalev', fathername: "Alexandrovich", age: 30 }]
+
+
+        //loop of persons
+        let persons = [
+            a = {
+                name: "Andrey",
+                surname: "Ivanov",
+                fathername: "Andreevich",
+                age: 21,
+                sex: "male"
+            },
+            b = {
+                name: "Igor",
+                surname: "Vasin",
+                fathername: "Igorevich",
+                age: 31
+            },
+            c = {
+                name: "Oleg",
+                surname: "Petrov",
+                fathername: "Olegovich"
+            }
+
+        ]
+        for (i = 0; i < persons.length; i++) {
+            console.log(persons[i].name + "  " + persons[i].surname)
+        }
+        //loop of loop of values
+        let persons = [
+            a = {
+                name: "Andrey",
+                surname: "Ivanov",
+                fathername: "Andreevich",
+                age: 21,
+                sex: "male"
+            },
+            b = {
+                name: "Igor",
+                surname: "Vasin",
+                fathername: "Igorevich",
+                age: 31
+            },
+            c = {
+                name: "Oleg",
+                surname: "Petrov",
+                fathername: "Olegovich"
+            }
+
+        ]
+
+        for (i = 0; i < persons.length; i++) {
+            for (let key in persons[i]) {
+                console.log(persons[i][key])
+            }
+
+        }
+
+        //fullName
+        let persons = [
+            a = {
+                name: "Andrey",
+                surname: "Ivanov",
+                fathername: "Andreevich",
+                age: 21,
+                sex: "male"
+            },
+            b = {
+                name: "Igor",
+                surname: "Vasin",
+                fathername: "Igorevich",
+                age: 31
+            },
+            c = {
+                name: "Oleg",
+                surname: "Petrov",
+                fathername: "Olegovich"
+            }
+
+        ]
+        for (let newkey of persons) {
+            if (newkey.name && newkey.surname) {
+                newkey.fullName = newkey.name + '  ' + newkey.surname;
+            }
+
+
+        } console.log(persons)
+
+        //serialize
+        JSON.stringify(persons)
+        '[{"name":"Andrey","surname":"Ivanov","fathername":"Andreevich","age":21,"sex":"male"},{"name":"Igor","surname":"Vasin","fathername":"Igorevich","age":31},{"name":"Oleg","surname":"Petrov","fathername":"Olegovich"}]'
+
+        //deserialize
+        '{"name":"Anna","surname":"Petrova","fathername":"Igorevna","age":24}'
+        let d = '{"name":"Anna","surname":"Petrova","fathername":"Igorevna","age":24}'
+        d = JSON.parse('{"name":"Anna","surname":"Petrova","fathername":"Igorevna","age":24}')
+        persons[3] = d;
+        console.log(persons)
+
+        // HTML
+        let persons = [
+            a = {
+                name: "Andrey",
+                surname: "Ivanov",
+                fathername: "Andreevich",
+                age: 21,
+                sex: "male"
+            },
+            b = {
+                name: "Igor",
+                surname: "Vasin",
+                fathername: "Igorevich",
+                age: 31
+            },
+            c = {
+                name: "Oleg",
+                surname: "Petrov",
+                fathername: "Olegovich"
+            },
+            d = {
+                name: "Anna",
+                surname: "Petrova",
+                fathername: "Igorevna",
+                age: 24
+            }
+        ]
+
+        let str = "<table border='1' cols = 4>"
+        for (let i = 0; i < persons.length; i++) {
+            str += `<tr><td>${persons[i].name}</td><td>${persons[i].surname}</td></tr>`
+        }
+        str += "</table>"
+
+        console.log(str)
+        document.write(str)
+
+        //HTML optional fields
+        let persons = [
+            a = {
+                name: "Andrey",
+                surname: "Ivanov",
+                fathername: "Andreevich",
+                age: 21,
+                sex: "male"
+            },
+            b = {
+                name: "Igor",
+                surname: "Vasin",
+                fathername: "Igorevich",
+                age: 31
+            },
+            c = {
+                name: "Oleg",
+                surname: "Petrov",
+                fathername: "Olegovich"
+            },
+            d = {
+                name: "Anna",
+                surname: "Petrova",
+                fathername: "Igorevna",
+                age: 24
+            }
+        ]
+        let str = "<table border='1' cols = 4>"
+        for (let i = 0; i < 4; i++) {
+            for (let key in persons[i]) {
+                str += `<tr><td>${key}</td><td>${persons[i][key]}</td></tr>`
+
+                
+            }
+        }str += "</table>"
+        console.log(str)
+        document.write(str)
+
+        //HTML tr color
+        let persons = [
+            a = {
+                name: "Andrey",
+                surname: "Ivanov",
+                fathername: "Andreevich",
+                age: 21,
+                sex: "male"
+            },
+            b = {
+                name: "Igor",
+                surname: "Vasin",
+                fathername: "Igorevich",
+                age: 31
+            },
+            c = {
+                name: "Oleg",
+                surname: "Petrov",
+                fathername: "Olegovich"
+            },
+            d = {
+                name: "Anna",
+                surname: "Petrova",
+                fathername: "Igorevna",
+                age: 24
+            }
+        ]
+        let str = "<table border='1' cols = 4>"
+        for (let i = 0; i < 4; i++) {
+            for (let key in persons[i]) {
+                str += `<tr style = "color: green; ><td>${key}</td><td>${persons[i][key]}</td></tr>`
+
+                
+            }
+        }str += "</table>"
+        console.log(str)
+        document.write(str)
+
+
+        //destruct array
+        if (key in a, b, c)
+            //destruct array
+            let arr = [1, 2, 3, 4, 5, "a", "b", "c"]
+        let [odd1, even1, odd2, even2, odd3, ...abc] = arr;
+        //destruct string
+        let arr = [1, "abc"]
+        let [number, ...abc] = arr;
+        let [a, b, c] = "abc";
+        let [s1, s2, s3] = [a, b, c];
+        //destruct 2
+
+        let obj = {
+            name: 'Ivan',
+            surname: 'Petrov',
+            children: [{ name: 'Maria' }, { name: 'Nikolay' }]
+        }
+
+        let {
+            children:
+            [{ name: name1 },
+                { name: name2 }
+            ] } = obj;
+
+
+
+        //destruct 3
+        let number = [1, 2, 3, 4, 5, 6, 7, 10];
+        let [a, b, { length = number.length }] = number
+
+
+
+    </script>
+</body>
+
+</html>