Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a tuple named 'person' with a name and age.
Swift
let person = ("John", [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a number for age.
Leaving the blank empty.
✗ Incorrect
The tuple holds a name and an age. The age should be a number like 30.
2fill in blank
mediumComplete the code to access the first element of the tuple 'coordinates'.
Swift
let coordinates = (x: 10, y: 20) let xValue = coordinates.[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the label 'y' instead of 'x'.
Using numeric indexes instead of labels.
✗ Incorrect
To get the x value from the tuple, use the label 'x'.
3fill in blank
hardFix the error in the code by completing the tuple declaration correctly.
Swift
let result = (status: "OK", code: [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting 200 in quotes, making it a string.
Using a boolean or nil instead of a number.
✗ Incorrect
The code expects an integer for 'code', so use 200 without quotes.
4fill in blank
hardFill both blanks to create a tuple with named elements and access the second element.
Swift
let point = ([1]: 5, [2]: 10) let yValue = point.y
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong labels that don't match the access.
Mixing up the order of labels.
✗ Incorrect
The tuple has labels 'x' and 'y'. We use 'y' to access the second element.
5fill in blank
hardFill all three blanks to create a tuple, access its elements, and print the name.
Swift
let person = ([1]: "Alice", [2]: 28) let name = person.[3] print(name)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong labels that don't match the tuple.
Accessing 'age' instead of 'name' when printing.
✗ Incorrect
The tuple has labels 'name' and 'age'. We access 'name' to print it.