Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solution(password) {
- function passLength(password) {
- if (password.length >= 6 && password.length <= 10) {
- return true;
- }
- console.log('Password must be between 6 and 10 characters');
- return false;
- }
- function content(password) {
- for (let digitLetter of password) {
- let asciiDigit = digitLetter.charCodeAt(0);
- let isSmallLetter = c => (asciiDigit >= 97 && asciiDigit <= 122);
- let isCapsLetter = c => (asciiDigit >= 65 && asciiDigit <= 90);
- let isNumber = c => (asciiDigit >= 48 && asciiDigit <= 57);
- if (!isNumber(asciiDigit) && !isCapsLetter(asciiDigit) && !isSmallLetter(asciiDigit)) {
- console.log('Password must consist only of letters and digits');
- return false;
- }
- }
- return true;
- }
- function countDigits(password) {
- let counter = 0;
- for(let char of password) {
- if(!isNaN(char)) {
- counter++;
- }
- }
- if (counter >= 2) {
- return true;
- }
- console.log('Password must have at least 2 digits');
- return false;
- }
- if (passLength(password) & content(password) & countDigits(password)) {
- console.log('Password is valid');
- }
- }
Add Comment
Please, Sign In to add comment