Challenge - 5 Problems
Kotlin REPL and Script Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of variable reassignment in Kotlin REPL
What is the output of the following Kotlin REPL session?
Kotlin
var x = 5 x = x + 3 println(x)
Attempts:
2 left
💡 Hint
Remember that 'var' allows reassignment in Kotlin.
✗ Incorrect
The variable x is initially 5, then increased by 3, so the output is 8.
❓ Predict Output
intermediate2:00remaining
Script mode output with top-level function
What will be printed when running this Kotlin script file?
Kotlin
fun greet(name: String) { println("Hello, $name!") } greet("Alice")
Attempts:
2 left
💡 Hint
Kotlin scripts allow top-level functions and execute statements immediately.
✗ Incorrect
The script defines a function and calls it immediately, printing the greeting.
❓ Predict Output
advanced2:00remaining
REPL session with shadowing and type inference
What is the output of this Kotlin REPL session?
Kotlin
val x = 10 val x = "Ten" println(x)
Attempts:
2 left
💡 Hint
In Kotlin REPL, you can shadow previous variables by redeclaring them.
✗ Incorrect
The second declaration shadows the first, so x is a String "Ten" when printed.
❓ Predict Output
advanced2:00remaining
Script mode with top-level statements and variable scope
What will be the output of this Kotlin script?
Kotlin
val a = 5 fun printA() { val a = 10 println(a) } printA() println(a)
Attempts:
2 left
💡 Hint
Local variables inside functions shadow outer variables.
✗ Incorrect
Inside printA(), local a=10 is printed. Outside, top-level a=5 is printed.
🧠 Conceptual
expert2:00remaining
Difference between Kotlin REPL and script mode execution
Which statement correctly describes a key difference between Kotlin REPL and Kotlin script mode?
Attempts:
2 left
💡 Hint
Think about how REPL and scripts handle code execution timing.
✗ Incorrect
REPL executes each entered line immediately and interactively; scripts run the whole file at once.