Gennadysht 2 rokov pred
rodič
commit
265a909d17

+ 19 - 0
js/12/hw12_04_check_01.html

@@ -0,0 +1,19 @@
+<header>Check result</header>
+
+<body>
+    <script>
+        function checkResult(original, validator) {
+            function wrapper(...params) {
+                let result = null;
+                while (validator(result = original(...params)) != true);
+                return result;
+            }
+            return wrapper;
+        }
+        const randomHigh = checkResult(Math.random, (x) => x >= 0.5);
+        alert(randomHigh());
+
+
+
+    </script>
+</body>

+ 19 - 0
js/12/hw12_04_check_02.html

@@ -0,0 +1,19 @@
+<header>Check result</header>
+
+<body>
+    <script>
+        function checkResult(original, validator) {
+            function wrapper(...params) {
+                let result = null;
+                while (validator(result = original(...params)) != true);
+                return result;
+            }
+            return wrapper;
+        }
+
+        const alwaysSayYes = checkResult(confirm, x => x);
+        alwaysSayYes();
+
+
+    </script>
+</body>

+ 40 - 0
js/12/hw12_04_check_03.html

@@ -0,0 +1,40 @@
+<header>Check result</header>
+
+<body>
+    <script>
+        function checkResult(original, validator) {
+            function wrapper(...params) {
+                let result = null;
+                while (validator(result = original(...params)) != true);
+                return result;
+            }
+            return wrapper;
+        }
+
+
+        const capitalize = str => {
+            if (!str)     // проверка пустой строки
+                return str;
+
+            str = str.toLowerCase().trim();
+            let result = str[0].toUpperCase() + str.slice(1);
+            return result;
+        }
+        const credentials = () => {
+            let sName = capitalize(prompt("Enter surname"));
+            let name = capitalize(prompt("Enter name"));
+            let fatherName = capitalize(prompt("Enter father name"));
+            let fullName = sName + ' ' + name + ' ' + fatherName;
+            return { name, sName, fatherName, fullName };
+        }
+        const respectMe = checkResult(credentials, obj => {
+            let hasEmptyField = !obj.sName || !obj.fatherName || !obj.name; //проверка пустого поля
+            return !hasEmptyField;
+        });
+
+        let res = respectMe();
+        alert(res.name + "\n" + res.sName + "\n" + res.fatherName + "\n" + res.fullName);
+
+
+    </script>
+</body>