subject

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 call the function and pass in a string that can be converted to an integer. 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.
func checkage(age: String)->Int?
{
if let age_type = Int(age)
{
if age_type > 18 {
return "Welcome!"
}
else if age_type < 18 {
return"Sorry, but you aren't old enough to use our app."
}
}
else {
return "Sorry, something went wrong. Can you please re-enter your age?"
}
return age_type
}

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 23:30
You picked the corridor which led you here. if the guards find you, they're going to be really angry! what is the synonym of angry
Answers: 1
question
Computers and Technology, 23.06.2019 09:20
How to print: number is equal to: 1 and it is odd number number is equal to: 2 and it is even number number is equal to: 3 and it is odd number number is equal to: 4 and it is even number in the console using java using 1 if statement, 1 while loop, 1 else loop also using % to check odds and evens
Answers: 3
question
Computers and Technology, 23.06.2019 17:00
In which of the following ways can using test-taking tips you? a. you can focus on the information that you need to study. b. you will see the answers to the test. c. you will study more. d. you will be less organized.
Answers: 1
question
Computers and Technology, 23.06.2019 20:40
On nba 2k 19, every time i try to join a my park game, it leads ro a website telling my dad that he needs ps plus. i already have ps plus though. how do i fix this?
Answers: 2
You know the right answer?
If an app asks for a user's age, it may be because the app requires a user to be over a certain age...
Questions
question
History, 10.06.2020 22:57
question
History, 10.06.2020 22:57
question
Mathematics, 10.06.2020 22:57
question
Mathematics, 10.06.2020 22:57
question
Mathematics, 10.06.2020 22:57
question
Social Studies, 10.06.2020 22:57
question
Mathematics, 10.06.2020 22:57
question
Mathematics, 10.06.2020 22:57
Questions on the website: 13722359