Beginner syntax error help needed

Hi Guys

Total beginner here.

I am working through a basic tutorial (literal basics) and although I have followed the tutorial exactly (my screen matches the tutorial screen) I am getting an error with the “a” variable. Does anyone have any suggestions as to why I am getting this error?

The only code is what is shown in the images.

Please note I am a total beginner and know very little about Kotlin or Android studio. Thanks in advance.

image4

1 Like

This is not allowed in kotlin
if you want to pass parameter you have to use like this

 fun main() {

    var avgvalues = avg(a= 3.4,b=2.5)
    var secondAvgValues = avg(3.2,2.5)

}

fun avg(a: Double, b: Double):Double {
    return a+b/2
}

Hi, thanks for the response.

The tutorial is using Kotlin and in a previous example using the ‘addUp’ function returns exactly the same error.

kotlin1

kotlin3

It is exactly what is on the screen in the tutorial and when he presses ‘run’ it returns ‘8’ in the console

Here is the tutorial link for reference -

That a: you see is not typed in by the user. It’s just IntelliJ showing that as a tip to tell you the name of the parameter in the function.

You can see it’s grayed out. Once you delete your “a:” IntelliJ should place that hint there.

Hi

Thanks, that’s great! The guy in the tutorial never explained that the a and b should be input automatically by the program.

Thanks for the help explaining this :+1:

Jon

By the way, these gray badges in the code are called “inlay hints”. You can turn them on or of in the settings of every JetBrains IDE. Just go to settings and search for inlay hints.

If you actually want to reference parameters by their name (named parameters), you have to use =. This is different from other languages (like Dart, for example).