Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to assign the maximum of two numbers to max.
Kotlin
val max = if (a > b) [1] else b
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
b in the if part instead of a.Trying to use statements instead of expressions.
✗ Incorrect
The if-else expression returns a if a is greater than b, otherwise b.
2fill in blank
mediumComplete the code to assign a message based on the score.
Kotlin
val message = if (score >= 50) [1] else "Try again"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the else message in the if part.
Forgetting to put quotes around the string.
✗ Incorrect
If the score is 50 or more, the message should be "Passed", otherwise "Try again".
3fill in blank
hardFix the error in the if-else expression to assign the correct value.
Kotlin
val result = if (num % 2 == 0) [1] else "Odd"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
Even without quotes causing a compile error.Returning a boolean or number instead of a string.
✗ Incorrect
The if-else expression must return a string in both cases. "Even" is the correct string for even numbers.
4fill in blank
hardFill both blanks to assign a grade based on the score.
Kotlin
val grade = if (score >= [1]) "A" else if (score >= [2]) "B" else "C"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the thresholds for
A and B.Using thresholds that overlap or are out of order.
✗ Incorrect
The highest grade A is for scores 90 and above, grade B for 80 and above, else C.
5fill in blank
hardFill all three blanks to assign a description based on temperature.
Kotlin
val description = if (temp < [1]) "Cold" else if (temp < [2]) "Warm" else [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using numbers instead of strings for descriptions.
Mixing up the order of temperature thresholds.
✗ Incorrect
Temperatures below 10 are "Cold", below 25 are "Warm", and 25 or above are "Hot".