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 trialScott Jaworski
3,019 PointsTelling me the variable "facts" is never used.
I've set the string, gotten facts.length, and then set fact = facts[randonNumber];. It's saying that facts is declared but never used. What?
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
//Create an Array [] indicate that this will be an array. elements of
//arrays are on per line.
String[] facts = {
"Ants stretch when they wake up in the morning.",
"Ostriches can run faster than horses.",
"Olympic gold medals are actually made mostly of silver.",
"You are born with 300 bones; by the time you are an adult you will have 206.",
"It takes about 8 minutes for light from the Sun to reach Earth.",
"Some bamboo plants can grow almost a meter in just one day.",
"The state of Florida is bigger than England.",
"Everyone is out to get you.",
"On average, it takes 66 days to form a new habit.",
"Mammoths still walked the earth when the Great Pyramid was being built.",
"treehouse is not actually in a tree"};
}
// The button was clicked, so update the fact label with a new fact.
//create a string called fact and assign it a blank string "";
String fact = "";
// create a variable called randomGenerator, make it new Random
Random randomGenerator = new Random(); //Contruct a new Random Number Generator
// take randomNumber and assign a random integer from RandomGenerator up to, but excluding 3
int randomNumber = randomGenerator.nextInt(facts.length);
fact = facts[randomNumber];
//Update the label with our dynamic fact
factLabel.setText(fact);
};