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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started