Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a lambda that adds two integers.
Kotlin
val sum: (Int, Int) -> Int = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for lambda declaration.
Trying to use 'fun' keyword inside lambda assignment.
Using incorrect lambda syntax like 'lambda(...)'.
✗ Incorrect
In Kotlin, lambdas are declared with curly braces and parameters before the arrow.
2fill in blank
mediumComplete the code to declare a lambda that returns the length of a string.
Kotlin
val length: (String) -> Int = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces.
Trying to declare lambda with 'fun' keyword.
Using incorrect lambda syntax like 'lambda(...)'.
✗ Incorrect
Lambda syntax uses curly braces with parameters and arrow before the expression.
3fill in blank
hardFix the error in the lambda declaration that multiplies two numbers.
Kotlin
val multiply: (Int, Int) -> Int = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of curly braces for lambda.
Trying to use 'fun' keyword inside lambda assignment.
Using 'lambda' keyword which is not valid in Kotlin.
✗ Incorrect
Kotlin lambdas require curly braces with parameters and arrow inside.
4fill in blank
hardFill both blanks to declare a lambda that checks if a number is even.
Kotlin
val isEven: (Int) -> Boolean = { num [1] num [2] 2 == 0 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' or '+' instead of '%' for remainder.
Using '=' instead of '==' for comparison.
✗ Incorrect
The lambda uses modulo operator '%' to check remainder and '==' to compare with zero.
5fill in blank
hardFill all three blanks to create a lambda that filters a list of strings by length greater than 3.
Kotlin
val filtered = words.filter { [1] -> [2].length [3] 3 } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for comparison.
Using different parameter names inconsistently.
✗ Incorrect
The lambda parameter is 'word', and it checks if word.length is greater than 3.