Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a message about iOS users.
iOS Swift
print("iOS users are often [1] buyers.")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'budget' because it sounds like a user type.
Selecting 'casual' which does not relate to spending.
✗ Incorrect
iOS users are generally considered premium buyers because they tend to spend more on apps and services.
2fill in blank
mediumComplete the code to check if a user is premium.
iOS Swift
if user.spending > [1] { print("User is premium") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 0 or 10 which are too low to define premium users.
✗ Incorrect
A spending threshold of 100 is used to identify premium users who spend more.
3fill in blank
hardFix the error in the code to identify premium users.
iOS Swift
let isPremium = user.spending [1] 100 if isPremium { print("Premium user") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' which only matches exactly 100.
Using '<' which is the opposite of what we want.
✗ Incorrect
Using '>=' checks if spending is equal or greater than 100, correctly identifying premium users.
4fill in blank
hardFill both blanks to create a function that returns true for premium users.
iOS Swift
func isPremiumUser(spending: Int) -> Bool {
return spending [1] [2]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' which would mark low spenders as premium.
Using 50 instead of 100 as the threshold.
✗ Incorrect
The function returns true if spending is greater or equal to 100, marking premium users.
5fill in blank
hardFill all three blanks to create a dictionary filtering premium users.
iOS Swift
let premiumUsers = users.filter { $0.spending [1] [2] }.map { $0.[3] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which filters low spenders.
Mapping to wrong property instead of 'name'.
✗ Incorrect
We filter users spending more than 100 and map to their names to get premium user names.