Advertisement
Marin171

js

Nov 12th, 2022
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. function solve(args) {
  2.  
  3. let password = args;
  4.  
  5. let isPasswordLengthValid = isValidLength(password);
  6.  
  7. if (!isPasswordLengthValid) {
  8. console.log("Password must be between 6 and 10 characters");
  9. }
  10.  
  11. let isPasswordContentValid = isValidContent(password);
  12. if (!isPasswordContentValid) {
  13. console.log("Password must consist only of letters and digits");
  14. }
  15.  
  16. let isPasswordCountDigitsValid = isValidCountDigits(password);
  17.  
  18. if (!isPasswordCountDigitsValid) {
  19. console.log("Password must have at least 2 digits");
  20. }
  21.  
  22. if (isPasswordLengthValid && isPasswordContentValid && isPasswordCountDigitsValid) {
  23. console.log("Password is valid");
  24. }
  25.  
  26. }
  27.  
  28. let isValidLength(password) {
  29.  
  30. if (password.length() >= 6 && password.length() <= 10) {
  31. return true;
  32. } else {
  33. return false;
  34. }
  35. //return password.length() >= 6 && password.length() <= 10;
  36. }
  37.  
  38. let isValidContent(password) {
  39.  
  40. for (char symbol : password.toCharArray()) {
  41. if (!Character.isLetterOrDigit(symbol)) {
  42. return false;
  43. }
  44. }
  45.  
  46. return true;
  47. }
  48.  
  49. let isValidCountDigits(password) {
  50. let countDigits = 0;
  51.  
  52. for (char symbol: password.toCharArray()) {
  53. if (Character.isDigit(symbol)) {
  54. countDigits++;
  55. }
  56. }
  57.  
  58. /*if (countDigits >= 2) {
  59. return true;
  60. } else {
  61. return false;
  62. }*/
  63.  
  64. return countDigits >= 2;
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement