Complete the code to define an extension function that adds a greeting to a String.
fun String.greet() = "Hello, " + [1]
The keyword this refers to the receiver object inside an extension function.
Complete the code to call the extension function on a String.
val name = "Alice" println(name[1]())
Extension functions are called like regular functions on the object, so parentheses are needed.
Fix the error in the extension function that tries to modify the original String.
fun String.addExclamation() {
[1] += "!"
}Strings are immutable in Kotlin, so you cannot modify this directly inside an extension function.
Fill both blanks to create an extension function that returns a new String with an exclamation mark added.
fun String.addExclamation() = [1] + [2]
The extension returns a new String by adding an exclamation mark to the original this String.
Fill all three blanks to create an extension function that repeats the String n times with a separator.
fun String.repeatWithSeparator(n: Int, sep: String) = (1..n).joinToString([1]) { [2] } + [3]
this inside the lambda.The function joins the String repeated n times separated by sep and adds an exclamation mark at the end.