In-Class Kotlin Exercise 1
Exercise · Explain This Kotlin Function (User Status)
Kotlin · Beginner
Explain this code out loud like you're speaking during a technical interview. Focus on the function, parameter, Boolean condition, if/else logic, and returned value.
fun getUserStatus(isOnline: Boolean): String {
if (isOnline) {
return "User is online"
} else {
return "User is offline"
}
}
fun main() {
println(getUserStatus(true))
}
🎯 Instructions oral task
- Explain what the function does.
- Describe what the parameter represents.
- Explain what a Boolean value is.
- Explain how the if/else statement works.
- Explain what gets printed to the console.
📖 Vocabulary core
- function — reusable block of code that performs a task.
- parameter — input value passed into a function.
- Boolean — data type that can be true or false.
- condition — a rule or check that controls what happens next.
- if/else statement — logic that chooses between two possible paths.
- return value — value sent back from a function.
- console output — text displayed on the screen.
🧩 Collocations natural English
- define a function
- pass in a Boolean value
- check a condition
- return a string
- execute a block of code
- print the result
🗣️ Phrasal Verbs interview speech
- pass in — “We pass in a Boolean value to the function.”
- check for — “The function checks for whether the user is online.”
- go through — “The program goes through the if/else logic.”
- print out — “The program prints out the final user status.”
🎤 Model Answer spoken
This Kotlin function is called getUserStatus. It takes one parameter called isOnline, which is a Boolean value. That means it can only be true or false.
Inside the function, there is an if/else statement. If isOnline is true, the function returns the string "User is online".
If isOnline is false, the function returns the string "User is offline". So the function chooses a message based on the user's online status.
In the main function, we call getUserStatus(true). Since the value is true, the program prints User is online to the console.