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


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:

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?


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?


Here’s how I did it:

var pubDrinks: List<String> = listOf("mead", "wine", "LaCroix")

Then when I do a println(pubDrinks) it returns: [mead, wine, LaCroix]