Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build an Interactive Story App (Retired) Finishing the User Interface Review: Adding Story Pages

Build an Interactive Story App

Complete this code. We want to format the 'jokeText' String to include the value of the 'animal' variable. 'jokeText' already has the appropriate placeholder.

String animal = "monkey____"; jokeText = String.format(, )____; mTextView.setText(jokeText);

1 Answer

Kevin Faust
Kevin Faust
15,353 Points


Since "jokeText already has the appropriate placeholder.", we can do the following:

jokeText = String.format(jokeText, animal);

We update the jokeText variable by taking the jokeText and then replacing some placeholder value in jokeText with the value of the animal variable.

heres an example:

lets say jokeText = "I like %s" (%s is a way to format strings)

if we call the code at the very top, then jokeText will end up being "I like monkeys" because the animal variable has the string value of "monkeys". we plop the 2nd param of String.format into the placeholder of the the 1st param. does it make sense?

Im still stuck

Hmm, I tried this exact solution, but the quiz marked it as incorrect. Maybe they're looking for something else? I also took a look at the Java docs, and they don't attempt to use the format function the same way Treehouse wants us to.