The Below code gives me the "Incompatible types:Boolean and Int". Not sure what might be the issue.
var votersAge = 17
var cardEligibility = when(votersAge)
{
(votersAge > 18) -> true
(votersAge <= 18) -> false
else -> false
}
You can think of
when(votersAge)
as a expression that in this case evaluates to anInt
. In when's body, the logic branches according to the value of the expression and so expects anInt
, you however provide a Boolean.when
expression/statement is documented hereTry this:
or alternatively, this: