Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Objective-C Basics More Operators! Logical Operators

Aaron Maguire
Aaron Maguire
4,645 Points

Where do I place the "AND"(&&) in this code?

Any suggestions? Thanks

variable_assignment.mm
bool isMediumSize;
int inchesTall = 64;
if ((inchesTall > 48)||(inchesTall < 68)){
  isMediumSize = true;
}

1 Answer

andren
andren
28,558 Points

You place it where you currently use || (OR). The OR operator returns true if either condition it is between is true, && (AND) returns true only if both of the conditions are true.

In your code you check if inchesTall is bigger than 48 or lesser than 68, instead of checking if it is bigger than AND less than as the task asked.

So simply replacing || with && like this:

bool isMediumSize;
int inchesTall = 64;
if ((inchesTall > 48)&&(inchesTall < 68)){
  isMediumSize = true;
}

Will allow your code to pass.