0
0
Kotlinprogramming~10 mins

It keyword for single parameter in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print each number using the 'it' keyword.

Kotlin
listOf(1, 2, 3).forEach { [1] -> println(it) }
Drag options to blanks, or click blank then click option'
Ait
Bnumber
Citem
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Writing an explicit parameter name when 'it' can be used.
Using a different variable name without declaring it.
2fill in blank
medium

Complete the code to filter numbers greater than 2 using 'it'.

Kotlin
val filtered = listOf(1, 2, 3, 4).filter { [1] > 2 }
Drag options to blanks, or click blank then click option'
Ait
Bnumber
Citem
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name without declaring it.
Forgetting to use 'it' inside the lambda.
3fill in blank
hard

Fix the error by replacing the blank with the correct implicit parameter.

Kotlin
val doubled = listOf(1, 2, 3).map { [1] * 2 }
Drag options to blanks, or click blank then click option'
Ax
Bit
Cnum
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using an undeclared variable name.
Trying to declare a parameter when 'it' can be used.
4fill in blank
hard

Fill both blanks to create a map of strings to their lengths using 'it'.

Kotlin
val lengths = listOf("apple", "banana", "cherry").associateWith { [1].[2] }
Drag options to blanks, or click blank then click option'
Ait
Blength
Dlengths
Attempts:
3 left
💡 Hint
Common Mistakes
Using an explicit parameter instead of 'it'.
Using a wrong property name for string length.
5fill in blank
hard

Fill all three blanks to filter and print strings longer than 4 characters using 'it'.

Kotlin
val longWords = listOf("cat", "elephant", "dog", "lion").filter { [1].[2] [3] 4 }
longWords.forEach { println(it) }
Drag options to blanks, or click blank then click option'
Ait
Blength
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using explicit parameter names instead of 'it'.
Using wrong comparison operator.