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!
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
Renan A4,425 Points
Concatenating an `if` statement
Why can't I just add
|| ("Jerk") instead of
noun.equalsIgnoreCase("Jerk") to an existing identical code
Because that's simply not how the language works. When you use || java will look at the two conditions on either side of it to see if either of them are true, it does not take the command on the left into account when it looks on the right, the conditions are considered entirely independent so chaining conditions is not possible in the way you demonstrate. Each condition needs to be a complete condition that would have been valid if it was used on it's own.
You could certainly argue that such a feature would be useful, but as it stands it's not a feature in the language, and a such it will just result in your code crashing if you attempted to do it.