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 trialDominik Flex
354 PointsJava - age
Hello,
when I type 13 I can do next steps. Why? 13 < 13 == false, if true 13 <= 13? Or?
Thanks.
3 Answers
Dominik Flex
354 PointsI solved them! :)
Michael Stedman
Full Stack JavaScript Techdegree Student 13,838 PointsDominik Flex I am sure that you figured out "a" solution, and have moved far beyond here by not, but I did want to take a little bit of time to touch on something as it is always best to find out why you were having the issue in the first place so that when it happens again in the future, you know what is going on and correct it immediately. Also, for anyone else who gets stumped at this same stage.
Your posted question is very confusing as to what you were having the problem with, and what the particular question you might have had was, but I am assuming that your issue was with the expression expression in the if
statement, combined with the assigning a certain integer value to the int age
variable. (Just for reference, Craig Dennis purposefully used the integer value of "12" to purposefully trigger the System.exit(0);
Altering that is where it appears that you came into your problems.
Now, one thing to keep in mind about if
statements is that the expression in the parenthesis is a "test"... It tests something; whatever it is in the equation. The result only comes out as a "Boolean" value, meaning that the result will come out with the true
or false
results.
Take the following if
statement for example (the same one from the video, and without the int age
being declared):
if (age < 13) {
// insert code here
console.printf("Sorry, you must be at least 13 to use this program.\n");
System.exit(0);
}
Looking at that if statement as what it is, and without having the variable age
having been declared yet, the expression in the parenthesis, being a test, is asking, "is the value of age
less than the integer 13?"
If the answer to that question is yes, then the result of the equation returns the Boolean value true
, which triggers the code that is in the code block below it, and those particular instructions are followed which ultimately ends with the program completely ending. If for some reason the testing of the equation was wrong, or a false
Boolean value, then it would proceed with the rest of the code OUTSIDE of that particular code block. In this instance, giving a false
Boolean value would skip the code block that encapsulated the code saying the user is too young for the program, then closing it immediately, and would then proceed with the game itself as if that test equation never happened.
Now, keep this in mind... The reason it looks like you had some sort of issue is because you were toying with different things that the instructor was not. In Java, just like nearly every other language, there are MANY ways to do one thing, so toying with something isn't at all a bad thing. You just need to know more about what you are doing when you go changing the values of variables and the operators. That is where I think that you ran into your problem, bud.
Hahah and trust me, I do quite a bit of tinkering my own self going through these courses. One of the best ways to learn the subject matter, and how to spot/correct possible future bugs, or even maybe avoid them all together.
I hope this helps, bud.
Philip Gales
15,193 PointsPlease elaborate more. I do not understand your question or problem.
Michael Stedman
Full Stack JavaScript Techdegree Student 13,838 PointsMichael Stedman
Full Stack JavaScript Techdegree Student 13,838 PointsI know that below you posted that you solved them, which is awesome, but I went ahead and posted an answer that broke down and explained where I might have seen you getting cross ways a bit. Just to help any if I could. Good luck on the rest of your journey, brotha-man! Your definitely learning from the best instructor on here (in my opinion anyways lol) Craig Dennis IS THE MAN! haha