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 trialLaz Alberto
284 PointsOperators not working?
whenever I type an operator with more than one equation (1+1 works fine, for example, but not 100 + 100 - 5 * 2 / 3 % 7) I get no result... what is happening!
Laz Alberto
284 PointsThanks Aaron, that's good to know. The problem actually resolved itself though. I closed xcode for a few hours and when I reopened, the equation worked as it was! Thanks a lot for responding, though!
1 Answer
Dave Berning
17,365 PointsTry using parentheses in your statement
var x = 1 + ((2 * 3) % 4)) // random numbers just for the example
if x < 5 {
// then do something
} else {
// then do something else
}
Laz Alberto
284 PointsThanks Dave, that's good to know. The problem actually resolved itself though. I closed xcode for a few hours and when I reopened, the equation worked as it was! Thanks a lot for responding, though!
Aaron Batchelder
3,240 PointsAaron Batchelder
3,240 PointsHey Laz. When you start writing a bunch of numbers like that with random operators you run into the order of operations. PEMDAS - Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. It's good to figure out how exactly you want the equation to execute before writing it. Keep in mind you can use parens to override the order of operations because P - Parentheses is executed first.