hw12_04_check_03.html 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <header>Check result</header>
  2. <body>
  3. <script>
  4. function checkResult(original, validator) {
  5. function wrapper(...params) {
  6. let result = null;
  7. while (validator(result = original(...params)) != true);
  8. return result;
  9. }
  10. return wrapper;
  11. }
  12. const capitalize = str => {
  13. if (!str) // проверка пустой строки
  14. return str;
  15. str = str.toLowerCase().trim();
  16. let result = str[0].toUpperCase() + str.slice(1);
  17. return result;
  18. }
  19. const credentials = () => {
  20. let sName = capitalize(prompt("Enter surname"));
  21. let name = capitalize(prompt("Enter name"));
  22. let fatherName = capitalize(prompt("Enter father name"));
  23. let fullName = sName + ' ' + name + ' ' + fatherName;
  24. return { name, sName, fatherName, fullName };
  25. }
  26. const respectMe = checkResult(credentials, obj => {
  27. let hasEmptyField = !obj.sName || !obj.fatherName || !obj.name; //проверка пустого поля
  28. return !hasEmptyField;
  29. });
  30. let res = respectMe();
  31. alert(res.name + "\n" + res.sName + "\n" + res.fatherName + "\n" + res.fullName);
  32. </script>
  33. </body>