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 trialatolagbe elijah
Front End Web Development Techdegree Student 464 Pointsplease why was a boolean used in the program is here any use,i dont really get it
i dont really get the boolean aspect
2 Answers
scribbles
21,173 PointsOkay, so a boolean is a data type just like String or Int, but a boolean has either a value of true or false.
In the first part of the video Craig is running a loop that will do something as long a certain condition evaluates to true:
do {
// Ignoring the code here
} while (noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk"))
As long as the string that is stored in the variable called noun is either "dork" or "jerk" the loop will continue to run.
Later in the video he extracts out this expression:
noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")
into a boolean variable called isInvalidWord which will store either true or false depending on whether or not the variable noun equals either "dork" or "jerk". He does this because he originally had that expression:
noun.equalsIgnoreCase("dork") || noun.equalsIgnoreCase("jerk")
twice in his code (at the 4:00 mark in the video it is on lines 26/27 as well as line 30) and duplicating the same code multiple times is bad practice so extracting it into its own variable solves this duplication.
atolagbe elijah
Front End Web Development Techdegree Student 464 PointsThanks a lot,i get it..:)