Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the variable obj is a String.
Kotlin
if (obj [1] String) { println("It's a string") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'is' for type checking.
Using 'instanceof' which is Java syntax, not Kotlin.
✗ Incorrect
The
is operator in Kotlin checks if an object is of a specific type.2fill in blank
mediumComplete the code to check if value is NOT an Int.
Kotlin
if (value ![1] Int) { println("Not an integer") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Placing the exclamation mark after 'is' instead of before.
Using '!=' instead of '!is' for type checking.
✗ Incorrect
The correct syntax to check if a value is NOT a type is to use
!is.3fill in blank
hardFix the error in the code to check if item is a Double.
Kotlin
if (item [1] Double) { println("It's a double") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Java's 'instanceof' instead of Kotlin's 'is'.
Using '==' which compares values, not types.
✗ Incorrect
Use the
is operator to check the type in Kotlin.4fill in blank
hardFill both blanks to check if data is a String and print its length.
Kotlin
if (data [1] String) { println(data[2]length) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of 'is' for type checking.
Using '.' or '?.' instead of '!!' which is appropriate after type check.
✗ Incorrect
Use
is to check type and non-null assertion operator !! to access length safely after type check.5fill in blank
hardFill all three blanks to check if input is NOT a List and print a message.
Kotlin
if (input [1] [2] [3]) { println("Input is not a list") }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the exclamation mark to negate the check.
Not closing the if condition with a parenthesis.
✗ Incorrect
Use '!is' to check NOT a type, specify 'List', and close the if condition with ')'.