Answered step by step
Verified Expert Solution
Link Copied!

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.image text in transcribed

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 20

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

Students also viewed these Databases questions

Question

A set of keys are picked up by a magnet.The keys are an example

Answered: 1 week ago