So I just recently started learning Kotlin through Google's new course and I learn how to randomly choose a number from a dice. I'm slightly confused on part of it so I tried to make a random coin flip program to help understand it better. I try to use the .random to choose between the two strings but it doesn't work and gives a long error. Here's the code so far:
fun main() {
val coinSide = Coin()
println("You flipped a ${coinSide}")
}
class Coin (){
fun flip() : String {
val head = ("Heads")
val tails = ("Tails")
return (head..tails).random()
}
}
Aucun commentaire:
Enregistrer un commentaire