0
0
Swiftprogramming~10 mins

Explicit type annotation in Swift - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a variable with an explicit type annotation.

Swift
var age: [1] = 25
Drag options to blanks, or click blank then click option'
AString
BBool
CInt
DDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using String instead of Int for numbers.
Forgetting to specify the type after the colon.
2fill in blank
medium

Complete the code to declare a constant with an explicit type annotation.

Swift
let pi: [1] = 3.14159
Drag options to blanks, or click blank then click option'
ADouble
BInt
CBool
DString
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int for decimal numbers causes errors.
Using String instead of a numeric type.
3fill in blank
hard

Fix the error in the code by adding the correct explicit type annotation.

Swift
var isActive: [1] = true
Drag options to blanks, or click blank then click option'
ABool
BString
CInt
DDouble
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int or String for boolean values.
Omitting the type annotation when it is required.
4fill in blank
hard

Fill both blanks to declare a variable with explicit type annotation and assign a string value.

Swift
var name: [1] = [2]
Drag options to blanks, or click blank then click option'
AString
B"John"
CInt
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int as the type for text.
Assigning a boolean value instead of a string.
5fill in blank
hard

Fill all three blanks to declare a constant with explicit type annotation and assign a boolean value.

Swift
let isEnabled: [1] = [2] // [3]
Drag options to blanks, or click blank then click option'
AInt
BBool
Ctrue
DThis declares a boolean constant
Attempts:
3 left
💡 Hint
Common Mistakes
Using Int as the type for boolean values.
Putting the boolean value in quotes making it a string.