The challenge answer(?) for Chapter 2: Unicorn's Horn


#1

For the drink menu, my first answer to the challenge is:

val drinkMenu = "Wine, " +"Mead, "+“LaCroix”

but this doesnt seem right because its just adding the drinks together. The obvious answer was to put the drinks into a list but I couldnt find anything online that shows me how to create array lists with strings like java

After searching, I found this: https://stackoverflow.com/questions/44239869/whats-the-kotlin-equivalent-of-javas-string

val drinks = arrayOf(“wine”, “mead”, “lacroix”)

I used arrayOf to store my drinks - however, running the code shows nothing on the log. What’s another way to list the drinks?


#2

Storing the drinks in an Array or some collection type is the right idea here, but the declaration of the array won’t print the elements (drink names) that it holds. If you want to print the menu, then you’ll need a way to iterate through the array - perhaps a loop or the forEach function?