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 trial

Java Java Basics Getting Started with Java Strings, Variables, and Formatting

code

Asked to write code with string and its giving me an error

console.printf("Hello, my name is %s\n", firstName);
console.printf("%s is learning how to write java\n", firstName);
console.printf("%s can code in java\n", firstName);

Moderator Edit: Added Markdown so the code is more readable in the Community Forum. When posting code, please refer to the Markdown Cheatsheet (link above "Post" button), or have a look at Treehouse's Markdown Basics Course.

String firstName = "Reece";

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi there,

While the code above is syntactically correct, it's not really what the challenge is asking for. Challenges are very specific and instruction need to be followed explicitly or the challenge will fail.

With that, the instruction for task # 1 states "Define a string variable named firstName that stores your name. Set the value to your name".. I don't see this code in the code you've posted.

And task two asks to "Call the printf method on the console object and make it write out "<YOUR NAME> can code in Java!". This I see in you code.

The third task is to use the %s which you also have done (this just modifies the line of code from task 2).

So, there should only be 2 lines of code for the three tasks. You're missing the first one and have two extra lines that were not asked for. Once you add the first line (for Task 1) and delete the other two. It will pass.

Nice work! :) :dizzy:

so what is the frist one im missing

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

You don't have the line of code that is defining and assigning a variable named firstName (Task 1 of the Challenge).

i do have that there