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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!