Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a is equal to b.
Swift
let isEqual = a [1] b Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' for comparison.
Using '!=' which checks for inequality.
✗ Incorrect
The operator == checks if two values are equal in Swift.
2fill in blank
mediumComplete the code to check if x is greater than y.
Swift
if x [1] y { print("x is greater") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which means less than.
Using '==' which checks equality.
✗ Incorrect
The operator > checks if the left value is greater than the right value.
3fill in blank
hardFix the error in the code to check if number is not equal to 10.
Swift
if number [1] 10 { print("Number is not 10") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which causes a syntax error in condition.
Using '==' which checks for equality, not inequality.
✗ Incorrect
The operator != checks if two values are not equal.
4fill in blank
hardFill both blanks to create a dictionary of words and their lengths, including only words longer than 3 characters.
Swift
let lengths = [String: Int](uniqueKeysWithValues: words.map { word in (word, word[1]) }).filter { $0.value [2] 3 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the filter condition.
Using '==' which only selects words of length exactly 3.
✗ Incorrect
.count gets the length of the word, and > filters words longer than 3 characters.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values greater than 0.
Swift
let result = Dictionary(uniqueKeysWithValues: data.map { ([1], [2]) in ([3], [2]) }).filter { $0.value > 0 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'item' instead of 'key' or 'value'.
Not converting the key to uppercase.
✗ Incorrect
key and value are tuple names, and key.uppercased() converts the key to uppercase.