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 trialAdnan Hasbi
4,544 PointsCode Challenge: Blog Reader Project Overview Question 4
Hey there stuck for question 4 of the Blog Reader App
Question:
Finally, write the 'message' variable to the log using the Log.d() method. For the first parameter of Log.d() (the tag), use “CodeChallenge”, and use the 'message' variable as the second parameter.
My Answer:
String title1 = "Android is awesome";
String title2 = "Mike is cool";
String title3 = "Treehouse loves me";
String[] titles ={ title1, title2, title3};
String message = title2;
Log.d(“CodeChallenge”,"message");
Please help ?
5 Answers
Ernest Grzybowski
Treehouse Project ReviewerFirst, we should take care of another problem. Your code should not have passed question number 3.
You entered:
String message = title2;
but the question asked "Now add a new String variable named 'message' and set it equal to the second element in the array."
The answer Ben Jakuben is definitely looking for is:
String message = titles[1];
Now onto question 4:
You tried to enter the variable with quotations around it. Java would take this literally and your Log message would have just read "message". This defeats the purpose of trying to use a variable.
Here is the correct answer:
String title1 = "Android is awesome";
String title2 = "Mike is cool";
String title3 = "Treehouse loves me";
String[] titles = {title1, title2, title3};
String message = titles[1];
Log.d("CodeChallenge", message)
Keep coding!
Mike Costa
Courses Plus Student 26,362 PointsHey Adnan,
In the Log.d() function, the second parameter should be the message variable, but in the code in your post, you have it passed in as a String.
Adnan Hasbi
4,544 PointsThank You.
However, still not sure how to fix it. I am relatively new in programming. Could it be shown in code from please ?
Adnan Hasbi
4,544 PointsYup it worked, Thanks so much Ernest :-)
Juan Gallardo
1,568 PointsThe answer by the mod forgot the ";" which means the complete answer is
String title1 = "Android is awesome";
String title2 = "Mike is cool";
String title3 = "Treehouse loves me";
String[] titles = {title1, title2, title3};
String message = titles[1];
Log.d("CodeChallenge", message);
Carl Taggett
10,321 PointsCarl Taggett
10,321 Points;