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
Aaron Charles-Rhymes
Courses Plus Student 8,434 PointsI was doing the Conditionals Quiz in iOS Development with Objective-C and not pass this question.
if ( i < 0 ){ printf("negative")
}_________________ ( i > 0 ) {
printf("positive");
}__________________ {
printf("zero"); }
1 Answer
Alvin Abia
Courses Plus Student 23,034 PointsWhen utilizing conditional statements in Objective-C that will account for more than 2 possible conditions, you can either use If-Else statements or Switch statements. The question on that quiz is referring to the use of the If-Else conditional statements.
- The general rule of thumb is that the first statement with a specific condition is written as an 'If' statement.
- Every other statement with a specific condition is written as an 'Else-If' statement.
- The last statement (that will usually refer to the condition that no other of your aforementioned conditions are fulfilled) is written as an 'Else' statement. Therefore, in the question, the completed conditional statement will look like this:
if ( i < 0 ){ printf("negative")
}
else if ( i > 0 ) {
printf("positive");
}
else {
printf("zero"); }
Aaron Charles-Rhymes
Courses Plus Student 8,434 PointsAaron Charles-Rhymes
Courses Plus Student 8,434 PointsI did not help, I put in the answer and it says that it was wrong P :(
Alvin Abia
Courses Plus Student 23,034 PointsAlvin Abia
Courses Plus Student 23,034 PointsI just looked at my answer and realized that it had a typo. I apologize for that. It should be 'else if', not 'else-if'. Let me know if that resolves it!
Aaron Charles-Rhymes
Courses Plus Student 8,434 PointsAaron Charles-Rhymes
Courses Plus Student 8,434 Pointsit worked thank you :) :) :) :)