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.

Java Java Basics Perfecting the Prototype Censoring Words - Looping Until the Value Passes

When he creates the variable isInvalidWord would it not be the same to make the variable into a String and not a boolean

Whats the difference? What is the boolean giving us that a String isn't?

1 Answer

Benjamin Schmiedel
Benjamin Schmiedel
3,160 Points
  • a boolean can only have two values "true" and "false"
  • a string can have infinit values (there a so many words you can build with chars)

conditions (if) use the simple way a boolean works. if the word (jerk) equals the word we would like to filter, then the boolean will be true


because of this the if statement will work. if statements couldn't work with strings

if("true"){code block}

would be invalid