Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Functions and Optionals Optionals Exercise: isDivisible function

Question - Amit says we can 'get a drink' before attempting to write our code. Can we have beer?

Problem, it's still morning.

6 Answers

Ha ha XD I was in one course with another instructor and he said we should take a drink too, to relax hahaha I think he said tea or coffee though. So, you don't need to have a "drink" like beer, water is a drink too. Drink water, it will be a good thing to do early in the morning.

John Adapon
John Adapon
15,769 Points

There is no rule on when not to drink beer and Walmart is open ;)

Rafael Schwemmer
Rafael Schwemmer
6,108 Points

I think "Drink" is an Optional here:

var drink: String? = "Beer"

We can then use a range and a for-in loop to consume a six pack by unwrapping each beer can in the loop with a !:

for number in 1...6 {
  println("Drinking \(drink!) number \(number)")
}

Output:

  • Drinking Beer number 1
  • Drinking Beer number 2
  • Drinking Beer number 3
  • Drinking Beer number 4
  • Drinking Beer number 5
  • Drinking Beer number 6

Warning: Optional Chaining with Vodka is not recommended, it will result in CRASH! ;-)

Brilliant!

"The best time to have a beer (or two) would be when you’re searching for an initial idea. Because alcohol helps decrease your working memory (making you feel relaxed and less worried about what’s going on around you), you’ll have more brain power dedicated to making deeper connections."

http://lifehacker.com/why-you-should-drink-beer-for-big-ideas-coffee-to-get-513262326

have a beer;)