Password validator


#1

i cant get my program to run, what is wrong with my code, im stuck on the 6th step. the output should say my code is valid but i get nothing! here is my code

function hasUppercase(input) {
for (var i = 0; i < input.length; i++) {
return true;
if (input[i] === input[i].toUpperCase()) {
return true;
}
}
}

function isPasswordValid(input) {
if (hasUppercase(input)) {
return true;
console.log('Password is Valid');
}
}

isPasswordValid('MelloYello');


#2

Is this all of your code for the lesson you are on?


#3

there is 12 steps but at the 6th step they ask you to run and the out is suppose to be "password is valid"

I dont get any output with current code

thanks for replying by the way


#4

Your function exits right before printing that.
Also, should that function really be printing anything? Seems like it's doing two things, both validating and printing.


#5

am not too sure what you mean by that...
exists right before printing that?

im trying to run the function to see if Mellow Yellow is valid, shouldnt i get some sort of output?

how can i fix this? also when i run hasUppercase funciton with same input, i also dont get a output.

thanks for replying. this is driving me crazy. lol


#6

i figured it out!

i had this:

function isPasswordValid(input) {
if (hasUppercase(input)) {
return true;
console.log('Password is Valid');
}
}

when it shouldve been this:

function isPasswordValid(input) {
if (hasUppercase(input)) {
console.log('Password is Valid');
return true;
}
}

console goes before return. (hopefully this helps someone)


#7

Only if you wrote code that says "hey, print stuff"

EXITS, see the line above the print, what does that do?


#8

I ran into this same problem. But I'm stuck on the next part. I don't know how to get the console to log that "password needs a capitol letter"


#9

I figured it out (if anyone reads this and has the same issue as me):

I was putting the:

if (!hasUpperCase(input)){
console.log('password needs a capital letter');
}

in the wrong place. It needs to go into the "isPasswordValid" function


#10

Thanks davidandrewlovi ! it helped me, same stuck with step 6