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 trialIvan Solodov
1,552 PointsIsn't it more efficient to just make factLebal.setText(facts[randomNumber]); instead of declaring the 'fact' String ?
I mean maybe I'm wrong or ahead of time , but just for the sake of it I just tried it and it worked fine . It seems much more straight forward than declaring the String fact , setting it to be equal to fact just to than set factLebal's text to fact's String. Please share your thoughts on the subject , Is it right to do this the way I described ? will it cause problems along the way ?
2 Answers
jason phillips
18,131 PointsThis is more efficient, and your program will technically use less memory. I tend to do write my code like that a lot. You may run into some issues if you were to wrap that code in a loop and do some large iteration, depending on what goes inside the function. In that case it would make sense to declare the variable separately.
Ivan Solodov
1,552 PointsYeah that's what I thought , I don't know much about loops yet tho . but i'll keep what you just told me in mind when ill get more into loops . Thanks !