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
John Cusack
1,061 PointsCrystal Ball gives prediction without shake when launched
When I launch the app on my phone it gives me a prediction without me shaking it. It is just sitting on my table and it only gives one prediction so I know I am not triggering the accelerometer.
1 Answer
Mike Bronner
16,395 Points(Please bear with me, as I can only give rough guesses as to what might be happening.)
Let's recap what we know:
- App starts and compiles without errors or warnings.
- Prediction runs without requiring the shaking of the phone.
- Prediction runs once.
That being established, we know that the code triggers the prediction, even though the phone is being shaken. This means there is an entry to the prediction routine in the code somewhere. This could be a while loop that is firing once, or an incorrect conditional statement, that is evaluating to TRUE, where you think it might be evaluating to FALSE.
Here's what I would do:
- Check the code surrounding the call to the prediction function(s).
- Place a breakpoint right before it.
- Place a few additional breakpoints before that at critical junctures (if statements, loops, etc.)
- Run the program and at each breakpoint check if the conditions are what you expect.
I suspect you will find something is happening you didn't expect, or you will find a small typo somewhere, i.e. using if(x = y) instead of if(x == y). Let me know if this helps you get to where you need to be.
Best of luck! ~Mike