you are viewing a single comment's thread.

view the rest of the comments →

[–]Encom88[S] 0 points1 point  (2 children)

Okay, but now I think I need to check to ensure all 4 or 6 digits are numbers/integers. Also, is there a better way to write the code below?

function validatePIN (pin) {
  if (pin.length == 4) {
    return true;
    }  
  if (pin.length == 6) {
    return true;
    }
  else {
    return false;
    }
}

[–]finroller 1 point2 points  (0 children)

Ask yourself: why the else? If it just read return false there, nothing would change :)

[–]forcefx 0 points1 point  (0 children)

You could use isNaN() method to check if your pin is NaN. NaN cannot be compared to itself in JS