Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created October 31, 2016 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/66c0ea420a76332bc9809fa81c83e703 to your computer and use it in GitHub Desktop.
Save codecademydev/66c0ea420a76332bc9809fa81c83e703 to your computer and use it in GitHub Desktop.
Codecademy export
function isPasswordValid(input) {
if (!hasUpperCase(input)) {
console.log('Password needs a capital letter');
}
if (!hasLowerCase(input)) {
console.log('Password needs a lower case letter.');
}
if (!isLongEnough(input)) {
console.log('Password should be at least 8 characters.');
}
if (!hasSpecialCharacter(input)) {
console.log('Password should contain one special character.');
}
if (hasUpperCase(input) && hasLowerCase(input) && isLongEnough(input) && hasSpecialCharacter(input)) {
console.log('The password is valid.');
}
}
function hasUpperCase(input) {
for (var i = 0; i < input.length; i++) {
if (input[i] === input[i].toUpperCase()) {
return true;
}
}
}
function hasLowerCase(input) {
for (var i=0; i < input.length; i++) {
if (input[i] === input[i].toLowerCase()) {
return true;
}
}
}
function isLongEnough(input) {
for (var i=0; i < input.length; i++) {
if (input.length >= 8) {
return true;
}
}
}
function hasSpecialCharacter(input) {
var specialCharacters = ['!', '@', '#', '$', '%', '^', '&', '*'];
for(var i = 0; i < input.length; i++) {
for (var j = 0; j < specialCharacters.length; j++) {
if (input[i] === specialCharacters[j]) {
return true;
}
}
}
}
isPasswordValid('FRAMSHINEDD@');
@GAllen113
Copy link

Does the isPassowordValid function supposed to come first? or does it even matter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment