vendredi 5 juin 2020

function needs to stop from executing when the condition is not met but it still executes

I'm trying to stop the function to be executed when the condition isn't met (if (numCharacter > "7" || numCharacter < "129") but for some reason it still executes when I test with invalid input (e.g 3 or 1000). Could anyone see what went wrong?


     if (numCharacter > 7 || numCharacter < 129) {

     if (numbers){
      resultArray = resultArray.concat(numbArray);

    }

     if (uppercases){
      resultArray = resultArray.concat(uppercaseArray);

    }

     if (lowercases){
      resultArray = resultArray.concat(lowercaseArray);

    }

     if (characters){
      resultArray = resultArray.concat(characterArray);
    }
    console.log(resultArray)


    for (var i = 0; i < numCharacter; i++) {

      userArray.push (resultArray[Math.floor(Math.random() * resultArray.length)]); 
      }



      return userArray.join("") ;


}

}

Aucun commentaire:

Enregistrer un commentaire