#Problem with Twofer Kotlin Problem

14 messages · Page 1 of 1 (latest)

tawny wadi
#

I wrote the correct code for the twofer problem:

fun main() {
    val name = readLine()
    val output = twofer(name)
    println(output)
}

fun twofer(name: String?): String {
    return if (name != null) {
        "One for $name, one for me."
    } else {
        "One for you, one for me."
    }
}```

But it keeps telling me:
```kt
[ERROR] src/test/kotlin/TwoFerTest.kt:[9,56] No value passed for parameter 'name'```

It also runs fine on an online compiler:
tacit sparrow
tawny wadi
#

I understand you

So the default value of the String parameter will be an empty String.

tacit sparrow
#

In your code, what do you use when the input is null?

tawny wadi
#

When the input is null, it would display One for you, One for me

tacit sparrow
#

So, what's the default name?

tawny wadi
#

you

tacit sparrow
#

Are you OK now? Tests passing?

tawny wadi
#

Not yet

tacit sparrow
#

Let us know what code you have now. Make sure to read the "default arguments" link I gave you.

tawny wadi
#

Got it. Very simple.

I read a Kotlin book deeply and I came back to solve the problem

vast ridgeBOT