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 trialAdam Łakomy
10,718 PointsI think switch would be much more appropriate
I know this is only a exercise but it could make bad habits to wannabe programmers. I have seen a lot of overuses of if-else statements like in this case. In my opinion you should figure out another example of using if-else and convert this video to show how to use switch or for loop with array.
Andrew Gay
20,893 PointsI am actually confused as to why we do not just directly assign the fact to the facts[randomNumber].... That would make more sense to me, then use the randomGenerator.nextInt(facts.length);
There are quite a few things I would have programmed differently
Daniel Hartin
18,106 PointsDaniel Hartin
18,106 PointsHi Adam
I agree that an overuse of if else statements are clumsy and hard to decipher when in the thick of it, but in my experience they are easier to understand that arrays which do seem to throw beginners especially when you have to explain that the first element is at position 0.
I think arrays are covered in this tutorial just a bit further down the line where they do exactly what you quite rightly point out is a preferred method (by us anyway) and use a random number to pull elements from an array.
Daniel