Question: 1. Create a function called checkPassword that takes optional string as parameter. 2. Inside the function, use guard statement that uses optional binding to check
1. Create a function called checkPassword that takes optional string as parameter.
2. Inside the function, use guard statement that uses optional binding to check if the password parameter is not nil and if it has at least 8 characters. If either of these conditions is not met, the guard statement triggers the else block, prints "Invalid password. It must be at least 8 characters long." and returns. If both conditions are met, the guard statement is passed, the function continues executing and prints "Password is valid."
3. Outside the function, create two optional string variables called password and password2 and assign pass and correctpassword respectively. 4. Use the checkPassword function to check the validity of password and password2.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
