Answered step by step
Verified Expert Solution
Question
1 Approved Answer
need some help with this, it was done in swift. Dont know im doing wrong. Lab-Optionals3. Exercise- Functions and Optionals If an app asks for
need some help with this, it was done in swift. Dont know im doing wrong.
Lab-Optionals3. Exercise- Functions and Optionals If an app asks for a user's age, it may be because the app requires a user to be over a certain age to use some of the services it provides. Write a function called checkAge that takes one parameter of type String. The function should try to convert this parameter into an Int value and then check if the user is over 18 years old. If he/she is old enough, print "Welcome!", otherwise print "Sorry, but you aren't old enough to use our app." If the String parameter cannot be converted into an Int value, print "Sorry, something went wrong. Can you please re-enter your age?" Call the function and pass in userInputAge below as the single parameter. Then cal the function and pass in a string that can be converted to an nteger 6 let userInputAge: String "34e" 7 func checkAge(Age: String?) ->Int? f if userInputAge = 18 { O Binary operator 'se cannot be applied to operands of type 'String' and'int' Binary operator 's' cannot be applied to operands of type 'String' and 'Int' 10 print( "Welcome.") else f 12 13 14 15 print "Sorry something went wrong.") Go back and update your function to return the age as an integer. Will your function always return a value? Make sure your return type accurately reflects this. Call the function and print the return value 19 20Step 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