Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a simple DSL function named config.
Kotlin
fun [1](block: Config.() -> Unit): Config { val config = Config() config.block() return config }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name that is too generic or unrelated to configuration.
✗ Incorrect
The DSL function is commonly named
config to clearly indicate configuration setup.2fill in blank
mediumComplete the code to declare a mutable property host inside the Config class.
Kotlin
class Config { var [1]: String = "" }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated property names like
port or url here.✗ Incorrect
The property
host holds the hostname in the configuration.3fill in blank
hardFix the error in the DSL usage by completing the code to set the port property inside the config block.
Kotlin
val conf = config {
port = [1]
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning port as a string instead of an integer.
✗ Incorrect
The
port property is an integer, so assign it a number without quotes.4fill in blank
hardFill both blanks to define the Config class with host and port properties.
Kotlin
class Config { var [1]: String = "" var [2]: Int = 0 }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing property names or types incorrectly.
✗ Incorrect
The
host is a string and port is an integer property in the configuration.5fill in blank
hardFill all three blanks to create a DSL function config that returns a configured Config object with host and port properties.
Kotlin
fun [1](block: Config.() -> Unit): Config { val config = [2]() config.[3]() return config }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function or variable names, or forgetting to call the lambda.
✗ Incorrect
The function is named
config, creates a Config instance, and calls the block lambda on it.