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 Introduction to Operators and Conditionals Review IF / ELSE

Hi! I,am again with if else training!

variable_assignment.mm
bool hasBonus;
int powerPoints=5;
if (powerPoints>3;)
  hasBonus= false;
else {powerPoints<=3;}
       hasBonus= true;

3 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

powerPoints needs to equal 0. Also, use an if-else statement:

Task 1

bool hasBonus;
int powerPoints = 0;

Task 2

if (powerPoints < 3){
  hasBonus = false;
} else {
  hasBonus = true;
} 
Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points
  1. The first part of the if-statement is missing it's parentheses.
  2. You don't place a conditional for an else-statement.
  3. No semi-colons in if-statements
  4. Should hasBonus be set to true if you have more then 3 power points, and not the other way around?
bool hasBonus;
int powerPoints=5;

if (powerPoints > 3) {
  hasBonus= false;
} else {
   hasBonus= true;
}
bool hasBonus;
int powerPoints=5;
if (powerPoints <3){
hasBonus=false;
}
if (powerPoints>=3){
hasBonus=true;
}