Ellen Spertus
08/20/2022, 5:58 PM/**
* Prompts a user for their name and returns their response.
*/
fun getUserName(): String {
println("What is your name? ")
val newName = readln()
return newName
}
/**
* Prints a greeting, using the person's [name].
*/
fun greetUser(name: String) {
println("Hello, $name")
}
/**
* Carries on a brief conversation with a user.
*/
fun converse() {
val name = getUserName()
greetUser(name)
}
Tom Yuval
08/20/2022, 6:16 PMgetUserName
, which doesn’t seem to need to be there, given as that it is `println`; I guess the intention was to use print
? (If not, I’d remove the space.)Ellen Spertus
08/20/2022, 6:32 PMWhat do you mean by “use of values” (which is supposedly unidiomatic)? Is it the fact that various values are put in `val`s only to be used once immediately afterwards?Yes.
Small nitpick: there’s a space at the end of the printed string inThank you. I'm having them do things from the repl, which didn't do what I wanted when the space wasn't present, but I see it doesn't do what I want even when the space is present. 😄, which doesn’t seem to need to be there, given as that it is `println`;getUserName
getUserName()
What is your name?Ellen
res0: kotlin.String = Ellen
Phani Mahesh
08/23/2022, 10:05 AM