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 trialRanak Bansal
1,207 PointsWhat is the purpose of %s?
Why must we use the '%s' when calling a variable in our code? I am unable to understand what the %s does, and if it is being used to call our code, why do we have to type 'firstName' as well?
2 Answers
Steven Parker
231,269 PointsThe "%s" is a format specifier that serves as a placeholder in the template string for where the value of the variable will get plugged in. This particular one reserves space for a string variable, which is what the "s" stands for.
Sharena Bess
798 Pointsjust asking to piggyback off of the original for my understanding, so does the %s call any(all) strings in in the file thus why you have to specify firstName. like if I had another string I would just use %s but at the end call it like console.printf(), lastName;???
Steven Parker
231,269 PointsThe "%s" acts as a placeholder for the string that is supplied as an additional argument, after the template itself. So they both need to be passed as arguments inside the parentheses, like this: "console.printf("%s", lastName)
".