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

Android Build a Simple Android App Basic Android Programming Choosing a Random Fact

Dylan Carter
Dylan Carter
4,780 Points

Why the extra syntax?

im not really sure if im using syntax in the right connotation there but you know what i mean, why would we make this into 3 lines when we could do it all from one?

fact = facts[new Random().nextInt(facts.length)];

1 Answer

Suleyman Orazgulyyev
PLUS
Suleyman Orazgulyyev
Courses Plus Student 5,798 Points

I believe it is done to make it clear for the beginners, or someone who never coded before. For example, I did not use the "fact" variable at all. But regarding your code I do not know if it works because you did not create your random variable at all, but you allocated space for it by "new Random". I guess it's up to you to optimize your code, and see if it works :) That's how we all learn :)