Browse Source

HW_11 to be continue

Gennadysht 2 years ago
parent
commit
dbb3097144

+ 2 - 2
js/10/hw10_16_DOM highlight cross.html

@@ -11,7 +11,7 @@
                 let column = document.createElement("td");
                 column.innerText = i * j;
                 row.append(column);
-                column.onmouseover = () => {
+                column.onmouseover = function () {
                     for (let k = 0; k < 9; k++) {
                         table.rows[i - 1].cells[k].style.backgroundColor = "lightgrey";
                     }
@@ -20,7 +20,7 @@
                     }
                     column.style.backgroundColor = "grey";
                 }
-                column.onmouseout = () => {
+                column.onmouseout = function() {
                     for (let k = 0; k < 9; k++) {
                         table.rows[i - 1].cells[k].style.backgroundColor = "white";
                     }

+ 24 - 0
js/11/hw10_12_read array of objects.html

@@ -0,0 +1,24 @@
+<head>read array of objects</head>
+
+<body>
+    <script>
+
+        function readArrayOfObjects() {
+            const arr = [];
+            do {
+                let obj = null;
+                while ((key = prompt("Enter obj property name")) &&
+                    (val = prompt("Enter obj property value"))) {
+                    if (!obj)
+                        obj = {};
+                    obj[key] = val;
+                }
+                if (obj)
+                    arr.push(obj);
+            }
+            while (confirm("continue&&???..."))
+            return arr;
+        }
+        console.log(readArrayOfObjects());
+    </script>
+</body>

+ 21 - 0
js/11/hw10_131_rhomb new.html

@@ -0,0 +1,21 @@
+<head>rhomb</head><br>
+<br>
+
+<body>
+    <script>
+        let lineSize = +prompt("Enter Line size");
+        let printLine = function (num, lineSize) {
+            let leftOffset = (lineSize - num) / 2;
+            let str = '.'.repeat(leftOffset) + '#'.repeat(num) + '.'.repeat(leftOffset);
+            return str;
+        }
+        let a = "";
+        for (i = -lineSize + 1; i <= lineSize; i += 2) {
+            a += "<a style='font-family : monospace,monospace;'>" + printLine(lineSize - Math.abs(i), lineSize) + "</a><br>";
+        }
+
+
+        document.write(a);
+
+    </script>
+</body>

+ 24 - 0
js/11/hw10_13_rhomb.html

@@ -0,0 +1,24 @@
+<head>rhomb</head><br>
+<br>
+
+<body>
+    <script>
+        let lineSize = +prompt("Enter Line size");
+        let printLine = function (num, lineSize) {
+            let leftOffset = (lineSize - num) / 2;
+            let str = '.'.repeat(leftOffset) + '#'.repeat(num) + '.'.repeat(leftOffset);
+            return str;
+
+        }
+        let a = "";
+        for (i = 1; i <= lineSize; i += 2) {
+            a += "<a style='font-family : monospace,monospace;'>" + printLine(i, lineSize) + "</a><br>";
+        }
+        for (i = lineSize - 2; i > 0; i -= 2) {
+            a += "<a style='font-family : monospace,monospace;'>" + printLine(i, lineSize) + "</a><br>";
+        }
+
+        document.write(a);
+
+    </script>
+</body>

+ 10 - 6
js/11/hw11_01_create_person.html

@@ -2,16 +2,20 @@
 
 <body>
     <script>
-        function getFullName(/*this*/) { //никаких this тут объявлять не надо, они подразумеваются
-            return `${this.name} ${this.surname}`
+        let createPerson = function (name, surname) {
+            let result = { 'name': name, 'surname': surname };
+            result.getFullName = function () {
+                return `${this.name} ${this.surname}`;
+            }
+            return result;
         }
         const a = createPerson("Вася", "Пупкин")
         const b = createPerson("Анна", "Иванова")
         const c = createPerson("Елизавета", "Петрова")
 
-        console.log(a.getFullName()) //Вася Пупкин
-        a.fatherName = 'Иванович'    //Вася Иванович Пупкин
+        console.log(a.getFullName()) 
+        a.fatherName = 'Иванович'    
 
-        console.log(b.getFullName()) //Анна Иванова
+        console.log(b.getFullName()) 
     </script>
-</body> 
+</body>

+ 61 - 8
js/11/hw11_02_createPersonClosure.html

@@ -1,13 +1,66 @@
 <head>createPersonClosure</head>
+
 <body>
     <script>
-        const a = createPersonClosure("Вася", "Пупкин")
-const b = createPersonClosure("Анна", "Иванова")
-console.log(a.getName())
-a.setAge(15)
-a.setAge(150) //не работает
-
-b.setFullName("Петрова Анна Николаевна")
-console.log(b.getFatherName()) //Николаевна
+        let createPersonClosure = function (name, surName) {
+            let result = {};
+            let age = 17;
+            let fatherName = "Пупкович";
+            result.getName = () => name;
+            result.getSurName = () => surName;
+            result.getFullName = function () {
+                return `${result.getName()} ${result.getSurName()}`;
+            }
+            result.setFullName = (newFullName) => {
+                const arrFullName = newFullName.split(' ');
+                result.setFatherName(arrFullName[2]);
+                result.setSurName(arrFullName[0]);
+                result.setName(arrFullName[1]);
+
+            }
+            result.setName = (newName) => {
+                if (isUpperCase(newName[0])) {
+                    name = newName;
+                }
+                else
+                    alert("wrong Name format");
+            }
+            result.setSurName = (newSurName) => {
+                if (isUpperCase(newSurName[0])) {
+                    surName = newSurName;
+                }
+                else
+                    alert("wrong Surname format");
+            }
+            result.setFatherName = (newFatherName) => {
+                if (isUpperCase(newFatherName[0])) {
+                    fatherName = newFatherName;
+                }
+                else
+                    alert("wrong Fathername format");
+            }
+
+            result.getAge = () => age;
+            result.setAge = (newAge) => {
+                if (newAge >= 0 && newAge <= 100)
+                    age = newAge;
+                else
+                    alert("wrong age: " + newAge);
+            }
+            result.getFatherName = () => fatherName;
+            return result;
+
+        }
+        const isUpperCase = (str) => str.toUpperCase() == str;
+
+        const a = createPersonClosure("Вася", "Пупкин");
+        const b = createPersonClosure("Анна", "Иванова");
+        console.log(a.getName());
+        a.setAge(15);
+        console.log(a.getAge());
+        a.setAge(150)
+
+        b.setFullName("Петрова Анна Николаевна");
+        console.log(b.getFatherName()); 
     </script>
 </body>

+ 60 - 1
js/11/hw11_03_create person destruct.html

@@ -2,8 +2,67 @@
 
 <body>
     <script>
+        const isUpperCase = (str) => str.toUpperCase() == str;
+        let createPerson = function (name, surName) {
+            let result = { 'name': name, 'surName': surName };
+            result.getFullName = function () {
+                return `${this.name} ${this.surName}`;
+            }
+            return result;
+        }
+        let createPersonClosureDestruct = function (obj) {
+            let result = {};
+            let { name = "Vasiya", surName = "Pupkin", fatherName = "Pupkovich", age = 17 } = obj;
+            result.getName = () => name;
+            result.getSurName = () => surName;
+            result.getFullName = function () {
+                return `${result.getName()} ${result.getSurName()}`;
+            }
+            result.setFullName = (newFullName) => {
+                const arrFullName = newFullName.split(' ');
+                result.setFatherName(arrFullName[2]);
+                result.setSurName(arrFullName[0]);
+                result.setName(arrFullName[1]);
+
+            }
+            result.setName = (newName) => {
+                if (isUpperCase(newName[0])) {
+                    name = newName;
+                }
+                else
+                    alert("wrong Name format");
+            }
+            result.setSurName = (newSurName) => {
+                if (isUpperCase(newSurName[0])) {
+                    surName = newSurName;
+                }
+                else
+                    alert("wrong Surname format");
+            }
+            result.setFatherName = (newFatherName) => {
+                if (isUpperCase(newFatherName[0])) {
+                    fatherName = newFatherName;
+                }
+                else
+                    alert("wrong Fathername format");
+            }
+
+            result.getAge = () => age;
+            result.setAge = (newAge) => {
+                if (newAge >= 0 && newAge <= 100)
+                    age = newAge;
+                else
+                    alert("wrong age: " + newAge);
+            }
+            result.getFatherName = () => fatherName;
+            return result;
+
+        }
+
+
         const a = createPersonClosureDestruct(createPerson("Вася Пупкин"))
         const b = createPersonClosureDestruct({ name: 'Николай', age: 75 })
-
+        console.log(a.getFullName());
+        console.log(b.getFullName());
     </script>
 </body>

+ 0 - 6
js/11/hw11_04_.html

@@ -1,6 +0,0 @@
-<head>_____</head>
-<body>
-    <script>
-        
-    </script>
-</body>

+ 18 - 0
js/11/hw11_04_insorted.html

@@ -0,0 +1,18 @@
+<head>insorted</head>
+
+<body>
+    <script>
+        let inSorted = (...args) => {
+            let prevVal = null;
+            for (el of args) {
+                if (prevVal != null && prevVal > el)
+                    return false;
+                prevVal = el
+            }
+            return true;
+
+        }
+        console.log(inSorted(1, 2, 3, 6, 8));
+        console.log(inSorted(1, 2, 3, 2, 8));
+    </script>
+</body>

+ 0 - 6
js/11/hw11_05_.html

@@ -1,6 +0,0 @@
-<head>_____</head>
-<body>
-    <script>
-        
-    </script>
-</body>

+ 24 - 0
js/11/hw11_05_testinSorted.html

@@ -0,0 +1,24 @@
+<head>test inSorted</head>
+
+<body>
+    <script>
+        let inSorted = (...args) => {
+            let prevVal = null;
+            for (el of args) {
+                if (prevVal != null && prevVal > el)
+                    return false;
+                prevVal = el
+            }
+            return true;
+
+        }
+        let arr = [];
+        while (a = prompt('Введите очередной элемент массива')) {
+            arr.push(a);
+            alert(arr);
+        }
+
+        console.log(inSorted(arr));
+
+    </script>
+</body>

+ 0 - 6
js/11/hw11_06.html

@@ -1,6 +0,0 @@
-<head>_____</head>
-<body>
-    <script>
-        
-    </script>
-</body>

+ 89 - 0
js/11/hw11_06_personForm.html

@@ -0,0 +1,89 @@
+<head>person Form</head>
+
+<body>
+
+
+    <script>
+        const setName = document.createElement('input')  ;
+        const setSurName = document.createElement('input') ;
+        const setFatherName = document.createElement('input') ;
+        const setAge = document.createElement('input') ;
+        const setFullName = document.createElement('input') ;
+        document.body.append(setName);
+        setName.innerText = "Name";
+        document.body.append(setSurName);
+        setSurName.innerText = "Surname";
+        document.body.append(setFatherName);
+        setFatherName.innerText = "Fathername";
+        document.body.append(setFullName);
+        setFullName.innerText = "Fullname";
+        document.body.append(setAge);
+        setAge.innerText = "Age";
+
+        nameInput.oninput = () => { };
+
+        const isUpperCase = (str) => str.toUpperCase() == str;
+        let createPersonClosure = function (name, surName) {
+            let result = {};
+            let age = 17;
+            let fatherName = "Пупкович";
+            result.getName = () => name;
+            result.getSurName = () => surName;
+            result.getFullName = function () {
+                return `${result.getName()} ${result.getSurName()}`;
+            }
+            result.setFullName = (newFullName) => {
+                const arrFullName = newFullName.split(' ');
+                result.setFatherName(arrFullName[2]);
+                result.setSurName(arrFullName[0]);
+                result.setName(arrFullName[1]);
+
+            }
+            result.setName = (newName) => {
+                if (isUpperCase(newName[0])) {
+                    name = newName;
+                }
+                else
+                    alert("wrong Name format");
+            }
+            result.setSurName = (newSurName) => {
+                if (isUpperCase(newSurName[0])) {
+                    surName = newSurName;
+                }
+                else
+                    alert("wrong Surname format");
+            }
+            result.setFatherName = (newFatherName) => {
+                if (isUpperCase(newFatherName[0])) {
+                    fatherName = newFatherName;
+                }
+                else
+                    alert("wrong Fathername format");
+            }
+
+            result.getAge = () => age;
+            result.setAge = (newAge) => {
+                if (newAge >= 0 && newAge <= 100)
+                    age = newAge;
+                else
+                    alert("wrong age: " + newAge);
+            }
+            result.getFatherName = () => fatherName;
+            return result;
+
+        }
+
+
+        const b = createPersonClosure("Анна", "Иванова")
+        b.setAge(15)
+        b.setFullName("Петрова Анна Николаевна")
+
+        function personForm(parent, person) {
+            //насоздавать инпутов (5 штук)
+            //надобавлять их в parent
+            //навесить каждому из них обработчик события типа nameInput.oninput = () => {
+            //тут пытаемся менять person используя person.setName. Текст в инпуте должен стать таким, который вернет setName
+            //}
+        }
+    </script>
+</body>