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 Immersive Examples Code Challenge

Create a while loop that will run as long as 'rubies' is less than 'rubyMax'. During each iteration of the loop, increment 'rubies' by 'rubyReward'. When the loop completes, assign a value of true to 'levelFinished'.

bool levelFinished;
int rubies = 0;
int rubyReward = 7;
int rubyMax = 50;

while (rubies <= rubyMax){
  rubies = rubies + rubyReward;
  if (rubies >= rubyReward){
    levelFinished = TRUE;
    break;
  }
}
Error i get "Oops! It looks like Task 1 is no longer passing."

But task one is perfect. Task one was to initialize these two:

bool levelFinished;
int rubies = 0;

2 Answers

This code passes for me:

bool levelFinished;
int rubies = 0;
int rubyReward = 7;
int rubyMax = 50;

while(rubies < rubyMax){
  rubies += rubyReward;
}
levelFinished = true;

Turns out that it does ask you to use the lowercase form of bool, but the two things you were doing in your code is that you were having the loop run while rubies <= rubyMax, where it should simply be <. Also, the way you were setting levelFinished to true was kinda weird, and should just be moved outside the loop, because it will run when the loop is finished

Okay. I thought when rubies equal rubymax i was supposed to break the loop and make levelfinished to True

When rubies equals rubyMax, the loop will end on its own (due to the condition rubies < rubyMax), and will then move onto whatever code comes after the loop. That's a good spot to set levelFinished to true

The problem is probably with your levelFinished variable. Declaring a boolean in Objective-C as bool (lowercase), is technically valid in most cases, but you need to use the lowercase true and false with it. In Objective-C, it's way more common (and accepted as the correct way) to use the all-caps BOOL (uppercase). That's set using an all-caps YES and NO. What I bet you meant to do was declare levelFinished like this:

BOOL levelFinished = NO; //Always set your variables to a logical initial value when you can

Then, later in the loop, I bet you meant to set it like this:

levelFinished = YES;

Still the same error. Not sure what is going on. about to give up on objective c and move to swift lol

Nah, I would totally recommend sticking with Objective-C first. Can you link me to the challenge, so I can try it?