Advertisement
ErolKZ

Untitled

Aug 9th, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1.  
  2. function validatePIN (pin) {
  3.  
  4.  
  5. let bool = true;
  6.  
  7. let counter = 0;
  8.  
  9. for (let i = 0; i < pin.length; i++) {
  10.  
  11. if (Number(pin[i]) || Number(pin[i]) === 0 && pin[i] !== ' ') {
  12.  
  13. counter++;
  14.  
  15. }
  16.  
  17. }
  18.  
  19.  
  20.  
  21. if (counter !== pin.length) {
  22.  
  23. bool = false;
  24.  
  25. }
  26.  
  27.  
  28.  
  29.  
  30.  
  31. if ((pin.length === 4 || pin.length === 6) && bool === true) {
  32.  
  33. console.log(true);
  34.  
  35. } else {
  36.  
  37. console.log(false);
  38.  
  39. }
  40.  
  41.  
  42.  
  43. //return true or false
  44. }
  45.  
  46.  
  47. validatePIN('123');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement