Ad

shorter and faster

Code
Diff
  • function pinValidator(pin){
      if (![4,6].includes(pin.length)) return false
      if (pin.match(/^\d+$/)) return true
      return false
    }
    
    • function pinValidator(pin) {
    • var pinLength = pin.length;
    • var pinIsCorrect = (pinLength === 4 || pinLength === 6);
    • var onlyNumbers = pin.match (/^\d+$/);
    • if (pinIsCorrect && onlyNumbers){
    • return true;
    • console.log("TRUE");
    • }
    • else {
    • return false;
    • console.log("FALSE");
    • }
    • };
    • pinValidator('88888');
    • function pinValidator(pin){
    • if (![4,6].includes(pin.length)) return false
    • if (pin.match(/^\d+$/)) return true
    • return false
    • }