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 trialAndy Stevens
Front End Web Development Techdegree Graduate 20,417 PointsCan someone explain why if I set a Boolean value to false and then write an if else statement, the variable stays false?
Example code below:
boolean isWon = false; if(isWon == true){ System.out.println(“congrats you won”); }else { System.out.println(“Oops not quite, try again!”); }
1 Answer
seth aruby
10,111 PointsHey Andy, your conditional statement only checks to see if isWon==true, it doesn't actually change the value of isWon to be 'true'. Since you have declared isWon to be false, then it will always be false unless something in your code changes its value. Hope this helps...
Andy Stevens
Front End Web Development Techdegree Graduate 20,417 PointsAndy Stevens
Front End Web Development Techdegree Graduate 20,417 PointsHi Seth,
I did think that after I posted my comment, good to have my thoughts confirmed. Thank you for taking the time to answer.
I’ll admit logic is my enemy, is this something you can learn?