0
0
Swiftprogramming~10 mins

Why Swift is strongly typed - Test Your Understanding

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 a specific type in Swift.

Swift
var name: [1] = "Alice"
Drag options to blanks, or click blank then click option'
AString
Bint
Cfloat
Dboolean
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase types like int or boolean which are not valid in Swift.
2fill in blank
medium

Complete the code to declare a constant integer in Swift.

Swift
let age: [1] = 30
Drag options to blanks, or click blank then click option'
ADouble
BString
CInt
DBool
Attempts:
3 left
💡 Hint
Common Mistakes
Using Double or String instead of Int for whole numbers.
3fill in blank
hard

Fix the error in the code by specifying the correct type for the variable.

Swift
var isActive: [1] = true
Drag options to blanks, or click blank then click option'
Afloat
BString
Cint
DBool
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or incorrect types like int or float for Boolean values.
4fill in blank
hard

Fill both blanks to create a dictionary with String keys and Int values.

Swift
var scores: [[1]: [2]] = ["Math": 90, "Science": 85]
Drag options to blanks, or click blank then click option'
AString
BInt
CDouble
DBool
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up key and value types or using incorrect types like Double or Bool.
5fill in blank
hard

Fill all three blanks to create a typed array and access its first element.

Swift
var fruits: [[1]] = ["Apple", "Banana", "Cherry"]
let firstFruit: [2] = fruits[[3]]
Drag options to blanks, or click blank then click option'
AString
B0
DInt
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong types for the array or index, or wrong index number.