Step 7


#1

Hello,
I am having trouble understanding and getting the proper result for step 7. Below is my code:

function isPasswordValid(input) {
  if(hasUppercase(input)) {
    console.log('The password is valid.');
  } else if(!hasUppercase(input)) {
   console.log('The password needs a capital letter.');
  }
}

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



isPasswordValid('mellow yellow');

The instructions state that you must check if hasUppercase is false using the ! operator however when I run the current password I only get 'The password is valid' in my console. What am I missing?

Thanks


#2

Your password ( 'mellow yellow' ) contains a space character.

so ..
' ' === ' '.toUpperCase() comes out to be true and thus you get the message The password is valid.


#3

Got it. Thanks a lot