1 00:00:02,923 --> 00:00:05,567 In the English language, we have different parts of speech, 2 00:00:05,567 --> 00:00:08,309 like noun, adjective, preposition, verb. 3 00:00:08,309 --> 00:00:09,886 And then there are a bunch of rules 4 00:00:09,886 --> 00:00:12,601 that tell us how to put these different parts of speech together. 5 00:00:12,601 --> 00:00:19,341 So if I said something like, "Dog books my eats," 6 00:00:19,341 --> 00:00:22,033 you'd be like, "What the heck does that mean?" 7 00:00:22,033 --> 00:00:23,913 And if you didn't realize this before, 8 00:00:23,913 --> 00:00:25,867 apparently, you can't just stick two nouns 9 00:00:25,867 --> 00:00:28,108 in front of an adjective, in front of a verb. 10 00:00:28,108 --> 00:00:29,440 Doesn't work. 11 00:00:29,440 --> 00:00:34,764 But if I'd switched those and said, "My dog eats books," 12 00:00:34,764 --> 00:00:37,260 then you would totally know what I meant. 13 00:00:37,260 --> 00:00:38,910 I could even replace this verb "eats" 14 00:00:38,910 --> 00:00:42,765 with another verb like, I don't know, "throws", 15 00:00:42,765 --> 00:00:45,426 and it would still make grammatical sense, 16 00:00:45,426 --> 00:00:47,875 even if you can't imagine my dog throwing a book. 17 00:00:47,875 --> 00:00:49,991 So in programming, instead of parts of speech, 18 00:00:49,991 --> 00:00:52,125 we have these things called types. 19 00:00:52,125 --> 00:00:54,485 You've already seen one of these: numbers. 20 00:00:54,485 --> 00:00:57,067 We use numbers all the time in our drawing code. 21 00:00:57,067 --> 00:00:58,536 And just like in English, 22 00:00:58,536 --> 00:01:01,802 there are times it makes sense to use a number, and times when it doesn't. 23 00:01:01,802 --> 00:01:06,104 If I started typing in this background function, "100 minus", 24 00:01:06,104 --> 00:01:08,696 then whatever comes next better be a number, 25 00:01:08,696 --> 00:01:13,508 or at least something that evaluates to a number like "14 + 15." 26 00:01:13,508 --> 00:01:17,833 On the other hand, if I'd just typed "100 space", 27 00:01:17,833 --> 00:01:20,434 well, I can't really put a number after that 28 00:01:20,434 --> 00:01:23,815 because "100-space-10" doesn't mean anything. 29 00:01:23,815 --> 00:01:27,534 So there's another type in programming, called the Boolean type. 30 00:01:27,534 --> 00:01:29,133 And it's called Boolean 31 00:01:29,133 --> 00:01:33,631 because some dude named George Boole invented it. 32 00:01:33,631 --> 00:01:37,394 And unlike a number which has a ton of possible values, 33 00:01:37,394 --> 00:01:42,031 a Boolean can only be one of two values: true or false. 34 00:01:43,000 --> 00:01:44,932 And you can see when I type them they turn blue, 35 00:01:44,932 --> 00:01:47,333 which means they're super special awesome words. 36 00:01:47,333 --> 00:01:49,433 And you've already seen one place where we use booleans, 37 00:01:49,433 --> 00:01:52,036 though you may not have realized it: if statements! 38 00:01:52,036 --> 00:01:53,968 Let's get a quick refresh on how those work. 39 00:01:53,968 --> 00:01:58,931 I'm just going to make a variable called 'number, ' give it a number, 40. 40 00:01:58,931 --> 00:02:01,499 And write an If statement that says, 41 00:02:01,499 --> 00:02:08,707 "If number is less than 50, then I will draw this first ellipse." 42 00:02:10,795 --> 00:02:13,044 I'm just going to copy this into the If statement 43 00:02:13,044 --> 00:02:16,234 and indent it by selecting everything and pressing tab. 44 00:02:16,234 --> 00:02:18,333 So now this statement says, 45 00:02:18,333 --> 00:02:22,772 "If number is less than 50," which it is, "then we'll draw the top ellipse." 46 00:02:22,772 --> 00:02:25,431 And if I make number greater than 50, 47 00:02:25,431 --> 00:02:28,434 you can see that the top ellipse disappears. 48 00:02:28,434 --> 00:02:30,573 Alright, so this thing inside the parentheses 49 00:02:30,573 --> 00:02:32,831 is actually a Boolean expression. 50 00:02:32,831 --> 00:02:36,164 Remember, a math expression is anything that evaluates to a number: 51 00:02:36,164 --> 00:02:40,204 like 3 plus 2 plus 4 times 8. 52 00:02:40,204 --> 00:02:43,801 So a Boolean expression is anything that evaluates to a Boolean. 53 00:02:43,801 --> 00:02:46,499 A good way to check if an expression evaluates to a Boolean, 54 00:02:46,499 --> 00:02:50,500 is to stick the word "is" in front of it, and ask it like a question. 55 00:02:50,500 --> 00:02:54,043 If it sounds like a yes or no question, then you know it's a Boolean expression. 56 00:02:54,043 --> 00:02:57,137 So here we can say, "Is number less than 50?" 57 00:02:57,137 --> 00:03:00,598 Yes, yes it is, and yes, that is a Boolean expression. 58 00:03:00,598 --> 00:03:04,173 On the other hand, if I had something like, "4 + 4" 59 00:03:04,173 --> 00:03:10,224 and I tried to ask, "is 4 + 4?" No. not a Boolean. 60 00:03:10,224 --> 00:03:12,065 So back to our If statement. 61 00:03:12,065 --> 00:03:14,573 I can actually put anything inside these parentheses, 62 00:03:14,573 --> 00:03:17,457 as long as it's a Boolean or Boolean expression. 63 00:03:17,457 --> 00:03:21,289 So I could say, "If true," and that ellipse would always be drawn. 64 00:03:21,289 --> 00:03:24,598 Or I could say, "If false," and the ellipse would never be drawn. 65 00:03:24,598 --> 00:03:28,699 I could also do something like "If 3 is less than 4," 66 00:03:28,699 --> 00:03:32,035 which is a Boolean expression that will always evaluate to true, 67 00:03:32,035 --> 00:03:34,664 which is kinda pointless, the ellipse will always be drawn, 68 00:03:34,664 --> 00:03:38,042 or "3 greater than 4," and that's always going to be false. 69 00:03:38,042 --> 00:03:41,049 And I can also assign Booleans to variables, like this: 70 00:03:41,049 --> 00:03:48,767 so I'm going to make a new variable, call it WinstonIsCool, and assign it 71 00:03:48,767 --> 00:03:51,500 a Boolean value, so true or false. 72 00:03:51,500 --> 00:03:54,274 Say true because Winston is definitely cool. 73 00:03:54,274 --> 00:03:57,047 And now that this variable has a Boolean value, 74 00:03:57,047 --> 00:04:00,444 I can copy it and stick it inside this If statement 75 00:04:00,444 --> 00:04:04,120 and now you can see the ellipse is drawn, 76 00:04:04,120 --> 00:04:06,731 because the value of WinstonIsCool is true. 77 00:04:06,731 --> 00:04:10,600 I could also replace this with a Boolean expression, 78 00:04:10,600 --> 00:04:14,200 so could be "2 less than 4." 79 00:04:14,200 --> 00:04:18,099 Now if you're making a variable that's meant for a Boolean value, 80 00:04:18,099 --> 00:04:19,602 you should give it a name 81 00:04:19,602 --> 00:04:21,997 that describes the condition when the variable is true. 82 00:04:21,997 --> 00:04:24,902 A good way to check if you've picked a good name for your variable 83 00:04:24,902 --> 00:04:28,330 is to put it in an If statement and see if it makes sense as a condition. 84 00:04:28,330 --> 00:04:31,434 So, forget WinstonIsCool, we already know that's true. 85 00:04:31,434 --> 00:04:34,306 Let's say I had a variable called "muffins." 86 00:04:34,306 --> 00:04:37,101 All right, "If muffins." Hmm. 87 00:04:37,101 --> 00:04:38,304 Well, you know what? 88 00:04:38,304 --> 00:04:42,169 That doesn't tell me anything, so that's a pretty bad variable name, 89 00:04:42,169 --> 00:04:46,166 but if I had "If muffinsAreBaking", then that would tell me 90 00:04:46,166 --> 00:04:50,931 that when this variable is true, then the muffins are baking. 91 00:04:50,931 --> 00:04:54,229 And don't ask me what muffins, it's not important. 92 00:04:54,229 --> 00:04:59,000 So for now let's go back to "If number is less than 50." 93 00:04:59,000 --> 00:05:00,383 Cool. 94 00:05:00,383 --> 00:05:02,538 Now let's look at some other Boolean expressions. 95 00:05:02,538 --> 00:05:05,772 You've already seen "less than" and "greater than", 96 00:05:05,772 --> 00:05:09,077 but you can also check if something is "less than or equal to." 97 00:05:09,077 --> 00:05:12,571 So let's try, "If number is less than or equal to 48." 98 00:05:12,571 --> 00:05:20,034 And we could also say, "If number is greater than or equal to 48." 99 00:05:20,034 --> 00:05:24,201 If it is, we will draw this top-right ellipse. 100 00:05:24,201 --> 00:05:27,375 Indent that. 101 00:05:27,375 --> 00:05:30,271 And if you'd like to check if two things are exactly equal to each other 102 00:05:30,271 --> 00:05:32,419 or you could say: "If number" 103 00:05:32,419 --> 00:05:36,281 and then three equals signs, or "triple equals 48." 104 00:05:39,494 --> 00:05:42,496 So that's a lot more like the equals sign you're used to in math, 105 00:05:42,496 --> 00:05:44,794 except this time you have three of them in a row. 106 00:05:44,794 --> 00:05:46,634 It's kind of overkill, right? 107 00:05:46,634 --> 00:05:48,899 And then finally, we have if you want to check 108 00:05:48,899 --> 00:05:51,235 if two things are not equal to, 109 00:05:51,235 --> 00:05:53,236 so strictly not equal to, you can say, 110 00:05:53,236 --> 00:05:57,601 "If number" and then an exclamation point, and then 2 equals signs, "48". 111 00:05:57,601 --> 00:06:02,134 And then we will draw that last ellipse. 112 00:06:04,096 --> 00:06:07,499 So if we go back to the top, we can see that number is 48, 113 00:06:07,499 --> 00:06:09,765 so it is less than or equal to 48, 114 00:06:09,765 --> 00:06:11,766 which is why the top-left ellipse is drawn. 115 00:06:11,766 --> 00:06:16,201 It's also greater than or equal to 48, it's also equal to 48, 116 00:06:16,201 --> 00:06:18,701 but it is not not equal to 48, 117 00:06:18,701 --> 00:06:21,630 which is why we're missing that bottom-right ellipse. 118 00:06:21,630 --> 00:06:23,803 And if we play around with number 119 00:06:23,803 --> 00:06:26,346 you can see it changes which ellipses are drawn. 120 00:06:26,998 --> 00:06:29,634 So now you guys know about Booleans. 121 00:06:29,634 --> 00:06:31,300 And just like math expressions, 122 00:06:31,300 --> 00:06:33,734 Boolean expressions can get really complicated. 123 00:06:33,734 --> 00:06:35,743 But we will talk about those another time.