Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add two integers and store the result.
Swift
let sum = 5 [1] 3
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
✗ Incorrect
The + operator adds two numbers together.
2fill in blank
mediumComplete the code to multiply two integers and store the result.
Swift
let product = 7 [1] 4
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition or division instead of multiplication.
✗ Incorrect
The * operator multiplies two numbers.
3fill in blank
hardFix the error in the code to correctly handle overflow addition.
Swift
let result = UInt8.max [1] 1
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using normal addition operator which causes runtime error on overflow.
✗ Incorrect
The &+ operator performs addition with overflow, wrapping around on overflow.
4fill in blank
hardFill both blanks to perform overflow subtraction and multiplication.
Swift
let difference = UInt8.min [1] 1 let product = 10 [2] 20
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using normal subtraction which causes error on underflow.
✗ Incorrect
&- subtracts with overflow wrapping, * multiplies normally.
5fill in blank
hardFill all three blanks to create a dictionary with keys as strings and values as overflow sums.
Swift
let results = ["a": 5 [1] 250, "b": 10 [2] 245, "c": 15 [3] 240]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using normal + operator which can cause overflow errors.
✗ Incorrect
Using &+ ensures addition wraps around on overflow for all values.