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 trialJakob Mick
1,872 PointsFun Facts App Repetition.
I am pretty new to Java and programming but I really want to improve the Fun Facts App. I tried to get rid of the repetition of colors and facts.
public int getColor() {
String color;
String lastColorPicked = String.valueOf(9);
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(mColors.length);
color = mColors[randomNumber];
if ( color == lastColorPicked ) {
return getColor();
}
else lastColorPicked = color;
String mLastColorPicked = mColors[randomNumber];
int colorAsInt = Color.parseColor(color);
return colorAsInt;
}
Can you do it like this at all? Or is it not possible? I know there is probably a better way to do it so if someone could show me how to make my code work and what the better code looks like that would be pretty neat.
And I'm really sorry if my code makes no sense at all but like I said I'm new to programming.