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
Ted Clayton
Courses Plus Student 206 PointsString equality objectives
Challenge Task 1 of 2 Add an if statement that checks to see if firstExample is equal to secondExample. If it is, print out "first is equal to second". ? My coding is below and it wouldn't run. However, once I took secondExample out of quotes it did run. Will someone explain why that is?
if (firstExample.equals("secondExample")) { console.printf("first is equal to second. \n\n");
2 Answers
Jennifer Nordell
Treehouse TeacherHi there! It's because secondExample is a variable name. Now that variable likely holds a string. But let's say firstExample holds the string "Treehouse". Let's also say that secondExample holds "Treehouse". When you put secondExample in quotes, you are giving a string literal. It will ask then if "Treehouse" is equal to "secondExample" (the string). What you want to know is if the value in firstExample and the value in secondExample are the same.
Hope this helps!
Ted Clayton
Courses Plus Student 206 PointsJennifer, Thank you for the reply.