In-Class Go Exercise 1
Exercise · Explain This Go Function (Check Admin User)
Go · Beginner
Explain this Go code out loud like you're speaking during a technical interview.
Focus on the function, the condition, the returned value, and the string comparison.
package main
import "fmt"
func isAdmin(role string) bool {
if role == "admin" {
return true
}
return false
}
func main() {
result := isAdmin("admin")
fmt.Println(result)
}
🎯 Instructions oral task
- Explain what the function does.
- Describe what the parameter represents.
- Explain the condition inside the if statement.
- Explain what happens when the role is "admin".
- Describe the returned boolean value.
- Explain what
fmt.Println()does.
📖 Vocabulary core
- function — reusable block of code that performs a task.
- parameter — input value passed into a function.
- string — data type used for text.
- boolean — value that is either true or false.
- condition — logical expression checked by the program.
- comparison operator — operator used to compare two values.
- return value — value sent back from a function.
🧩 Collocations natural English
- check the user role
- compare two strings
- return a boolean value
- pass a parameter into a function
- evaluate a condition
- print the result to the console
🗣️ Phrasal Verbs interview speech
- check for — “The function checks for the admin role.”
- pass in — “We pass in a string parameter.”
- carry out — “The condition carries out a comparison.”
- print out — “The program prints out the result.”
💬 Useful Interview Phrases communication
- “This function is responsible for checking...”
- “The parameter represents...”
- “The condition evaluates whether...”
- “If the condition is true, the function returns...”
- “Otherwise, the function returns false.”
- “Finally, the result is printed to the console.”
🎤 Model Answer spoken
This Go function checks whether a user has the admin role.
The function is called isAdmin and it accepts a string parameter named role.
Inside the function, there is an if statement that compares the value of the role variable with the string "admin".
The double equals operator is used to compare the two values.
If the condition is true, the function returns true. That means the user is an administrator. If the condition is false, the function returns false.
In the main function, we call the isAdmin function and pass in the value "admin".
The returned result is stored in the variable called result.
Finally, the program prints the result to the console using fmt.Println().