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

Devansh Sanghvi
PLUS
Devansh Sanghvi
Courses Plus Student 934 Points

Can anyone help me understand the code, i have some doubts in the code. What is q1 in the first place.

Through string Interpolation the value of q1 is (1,4) but when i ask the value of q1 at the end of the switch statement it shows an error saying "use of unresolved identifier q1".

let point = (x :1 , y: 4)

switch point {

case let q1 where (point.x > 0) && (point.y > 0): print(" (q1) is in quadrant 1")

default: break

}

2 Answers

Tassia Castro
seal-mask
.a{fill-rule:evenodd;}techdegree
Tassia Castro
iOS Development Techdegree Student 9,170 Points

Hey Devansh,

It is missing the backslash of the string interpolation. Try this:

let point = (x :1 , y: 4)
switch point {
    case let q1 where (point.x > 0) && (point.y > 0): print(" \(q1) is in quadrant 1") // I added this 
    default: break
}

q1 in this case is a constant declared inside switch (case let q1).

So, the code has a constant called point that has this value (x :1 , y: 4) . When you switch point, you are trying to discover if this point is in quadrant 1 (Math concept. All numbers greater than 0 are in quadrant 1).

You can read the code like this: case point.x is greater than 0 and point.y is greater than 0 so assign those values to the constant q1. After that you use the method print to print the value of q1.