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 trialGlenn Artistro Yadi
594 PointsChange the value of powerPoints to 5. Then create an if else statement such that when 'powerPoints' is less than 3 'hasB
i am stuck in this review
bool hasBonus;
hasBonus = powerPoints
int powerPoints;
powerPoints = 5 ;
if (powerPoints < 3 ) {
powerPoints = hasBonus;
}
else {
powerPoints = hasBonus;
1 Answer
Zachary Betz
10,413 PointsAs Oluwatobi said, you're mostly on the right track. So you've declared you're two variables, but you cannot assign powerPoints
(an int) to hasBonus
(a bool) . Delete that line.
You're checking for the correct thing in your IF
statement, but then you're assigning hasBonus
to powerPoints
. Instead, you should be setting hasBonus
to either true
or false
.
Once cleaned up, your answer should look similar to the below. Keep grinding. It'll come to you.
bool hasBonus;
int powerPoints = 0;
powerPoints = 5;
if (powerPoints < 3) {
hasBonus = false;
} else {
hasBonus = true;
}
Oluwatobi Popoola
10,447 PointsOluwatobi Popoola
10,447 PointsYou're mostly on the right track! The problem here though is you are setting the value of hasBonus, which is a Boolean, to the the value of powerPoint, which is an Integer. Also, the problem does not ask you to set them equal to each other.
(Also, you can't reference variables before they're officially declared.)
The if/else conditions look correct, so aim for making sure hasBonus is set to the correct conditions.
Hint: Booleans only have 2 possible values.