Error unresolved reference: isOdd

Hi All,
I am going through the kotlin tutorial(link below)

One of the example as part of “when” expression is

val x = 5
val y = 10
when {
x.isOdd() → print(“x is odd”)
y.isEven() → print(“y is even”)
else → print(“x+y is odd”)
}

However when i try to execute this code, i get an error
unresolved reference: isOdd
unresolved reference: isEven

https://pl.kotl.in/q5cC2kN2I

i have searched kotlin website and forums but could not find any results.

Please advice me to resolve this issue.

Thank you for your time and attention.

That was just an example, because it is rather obvious for the reader, what such isOdd and isEven do. Similarly, x and y in this example aren’t defined anywhere.

You can very easily create these functions by yourself:

fun Int.isOdd() = this % 2 != 0
fun Int.isEven() = this % 2 == 0
1 Like

Thank you for your guidance