Silver Challenge Binding Error

Hey everyone, new to Swift and getting an error with the if-case statement that has me stumped.

Using the following statement:

let age = 21

if case 18...35 = age, age >= 21 {
   print("In cool demographic and of drinking age")
}

I’m getting the following error on the if case statement:

Variable binding in a condition requires an initializer.

What am I missing here?

I pasted your code and it worked just fine

The following code produces the same syntax error; note the missing “= age”.

let age = 21

if case 18...35, age >= 21 {
   print ("In cool demographic and of drinking age")
}

I retested just now. It gives me the error you reported if I run your code with “= age” missing. everything is all right otherwise.

I tested both in IBM Swift Sandbox and in Xcode Playground

Just tested in the IBM sandbox and it worked fine also. So I took a closer look at my environment and realized I was on xCode 7.3 and an older version of Swift.

Updated xCode to 8.3.3 and Swift to 3.1 and the code compiles now fine.

Thanks everyone!

perfect!

:slight_smile: