12345678910111213141516171819202122232425262728293031323334353637383940 |
- <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>
|