0
0
Swiftprogramming~10 mins

Comparison operators 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 check if a is equal to b.

Swift
let isEqual = a [1] b
Drag options to blanks, or click blank then click option'
A==
B=
C!=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of '==' for comparison.
Using '!=' which checks for inequality.
2fill in blank
medium

Complete 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'
A>
B<=
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which means less than.
Using '==' which checks equality.
3fill in blank
hard

Fix 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'
A=
B!=
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which causes a syntax error in condition.
Using '==' which checks for equality, not inequality.
4fill in blank
hard

Fill 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'
A.count
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the filter condition.
Using '==' which only selects words of length exactly 3.
5fill in blank
hard

Fill 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'
Akey
Bvalue
Ckey.uppercased()
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'item' instead of 'key' or 'value'.
Not converting the key to uppercase.