lundi 19 octobre 2020

How to call a function from within an if-else statement?

I'm trying to call the pushChar function() within an if-else statement below it. The variable that I store the function in after execution is global, so why can't I call on it?


  function pushChar() {
  var randomPassword = [];
    for (var i = 0; i < pwLength; i++) {
      var item = passwordPool[Math.floor(Math.random() * passwordPool.length)];
      randomPassword.push(item);
      }
      return randomPassword;
    }
  var password = pushChar();
 

  //validate that all of the conditions were met.

  var checkUpper = (upperCaseChar.some(ele => password.includes(ele)))
  var checkLower = (lowerCaseChar.some(ele => password.includes(ele)))
  var checkNumeric = (numericChar.some(ele => password.includes(ele)))
  var checkSpecial = (specialChar.some(ele => password.includes(ele)))

  console.log(checkUpper);
  console.log(checkLower);
  console.log(checkNumeric);
  console.log(checkSpecial);


  if(checkUpper === confirmUpper && 
     checkLower === confirmLower && 
     checkNumeric === confirmSpecial && 
     checkSpecial === confirmNumber) {
      console.log(password);
   } else {
    alert("somethings missing");
    pushChar(); //why won't this run??
   }



//Presents randomly generated password to the user as a string. 
return password.join("");

  }```

Aucun commentaire:

Enregistrer un commentaire