AntonPyvovarov 1 year ago
parent
commit
6f89ebce35
2 changed files with 188 additions and 0 deletions
  1. 12 0
      HW5/index.html
  2. 176 0
      HW5/main.js

+ 12 - 0
HW5/index.html

@@ -0,0 +1,12 @@
+<!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>HW5</title>
+</head>
+<body>
+    <script src="main.js"></script>
+</body>
+</html>

+ 176 - 0
HW5/main.js

@@ -0,0 +1,176 @@
+// 3 persons,different fields and fields check
+let a = {
+    name: 'Petro',
+    surname: 'Petrovich',
+    "age": '30',
+    "fathername": 'Petroff',
+    "sex": 'male',
+}
+
+let b = {
+    name: 'Ivan',
+    surname: 'Ivanov',
+    "age": '35',
+    "fathername": 'Ivanovich',
+    "sex": 'male',
+}
+
+let c = {
+    name: 'Sveta',
+    surname: 'Svetova',
+    "age": '40',
+    "fathername": 'Serhiivna',
+    "sex": 'female',
+}
+
+if ("age" in a) {
+    alert(a.age);
+}
+
+if ("fathername" in a) {
+    alert(a.fathername);
+}
+
+if ("sex" in a) {
+    alert(a.sex)
+}
+
+if ("age" in b) {
+    alert(b.age);
+}
+
+if ("fathername" in b) {
+    alert(b.fathername);
+}
+
+if ("sex" in b) {
+    alert(b.sex)
+}
+
+if ("age" in c) {
+    alert(c.age);
+}
+
+if ("fathername" in c) {
+    alert(c.fathername);
+}
+
+if ("sex" in c) {
+    alert(c.sex);
+}
+
+// array of persons
+
+let persons = [a, b, c, { name: 'Olha', surname: 'Petrova', age: '45', sex: 'female' }];
+
+// loop of persons
+
+let output;
+for (output = 0; output < persons.length; ++output) {
+    console.log(persons[output])
+}
+
+// loop of name and surname
+
+let outputNameAndSurname;
+for (outputNameAndSurname = 0; outputNameAndSurname < persons.length; ++outputNameAndSurname) {
+    console.log(persons[outputNameAndSurname].name + " " + persons[outputNameAndSurname].surname);
+};
+
+// loop of loop of values
+
+for (let output = 0; output < persons.length; output++) {
+    for (let key in persons[output]) {
+        console.log(persons[output][key]);
+    }
+};
+
+// fullName
+
+for (let key of persons) {
+    if (key.name && key.surname) {
+        key.fullName = key.name + " " + key.surname;
+    }
+}
+console.log(persons);
+
+
+// serialize
+
+JSON.stringify(arrofPersons);
+
+//  deserialize
+
+let d = '{"name" : "Olha","surname" : "Petrova" ,"age" : 45,"sex":"female"}'
+d = JSON.parse(d)
+persons[3] = d
+console.log(persons)
+
+// HTML
+
+let str = "<table border='1'>";
+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 optional fields
+
+let strTwo = "<table border='1'>"
+for (let i = 0; i < 4; i++) {
+    for (let key in persons[i]) {
+        strTwo += `<tr><td>${key}</td><td>${persons[i][key]}</td></tr>`
+
+
+    }
+} strTwo += "</table>"
+console.log(strTwo)
+document.write(strTwo)
+
+// HTML tr color
+
+let strThree = "<table border='1'>";
+for (let i = 0; i < 4; i++) {
+    for (let key in persons[i]) {
+        strThree += `<tr style="color: blue;><td>${[key]}</td><td>${persons[i][key]
+            }</td></tr>`;
+    }
+}
+strThree += "</table>";
+console.log(strThree);
+document.write(strThree);
+
+// HTML th optional
+
+
+// destruct array
+{
+
+    let arr = [1, 2, 3, 4, 5, "a", "b", "c"]
+    let [odd1, even1, odd2, even2, odd3, ...letters] = arr
+
+    //destruct string
+    let arr2 = [1, "abc"]
+    let [number, [s1, s2, s3]] = arr2
+
+    // destruct 2
+
+    let obj = {
+        name: 'Ivan',
+        surname: 'Petrov',
+        children: [{ name: 'Maria' }, { name: 'Nikolay' }]
+    }
+
+    let {
+        children: [{ name: name1 }, { name: name2 }] } = obj;
+
+    //destruct 3
+    let numberTwo = [1, 2, 3, 4, 5, 6, 7, 10];
+    let [a, b, { length = numberTwo.length }] = numberTwo;
+    
+}