1 00:00:00,640 --> 00:00:01,560 OK, welcome back. 2 00:00:01,590 --> 00:00:04,980 Now we're on lesson 10, we're in to learn about the ternary operator. 3 00:00:05,410 --> 00:00:09,880 This is extremely similar to IF and L's short version. 4 00:00:10,000 --> 00:00:14,560 OK, so this is shorthand expression that's going to be the same as an IF and else. 5 00:00:15,190 --> 00:00:18,070 What's really nice is how concise the language is. 6 00:00:18,610 --> 00:00:24,490 All you're basically going to do is do the first condition that you're going to check for, just the 7 00:00:24,490 --> 00:00:25,300 same as if you did. 8 00:00:25,300 --> 00:00:35,920 If fruit is mango return that ls return that this is going to save you having to say return, save you 9 00:00:35,920 --> 00:00:36,910 having to say else. 10 00:00:37,330 --> 00:00:42,640 It's just going to put it all into this question mark you've really written out as a question. 11 00:00:43,360 --> 00:00:45,700 Is fruit the same as mango. 12 00:00:46,360 --> 00:00:46,960 Hmm. 13 00:00:47,410 --> 00:00:52,250 If true it'll return this value and if false it will return the value after the colon. 14 00:00:52,750 --> 00:00:59,140 OK, so it uses a question mark after the conditional statement in a colon after the first return if 15 00:00:59,140 --> 00:01:00,070 the condition is met. 16 00:01:01,090 --> 00:01:02,480 So let's take a look at that in code. 17 00:01:04,600 --> 00:01:04,930 All right. 18 00:01:04,940 --> 00:01:13,240 So why don't we start with this example right here and let's bring this over to us in 10. 19 00:01:17,810 --> 00:01:18,290 All right. 20 00:01:19,440 --> 00:01:24,630 So we have Phyto is a we'll be happy soon. 21 00:01:24,850 --> 00:01:25,980 Let's make him happy again. 22 00:01:28,880 --> 00:01:29,960 Phyto is a happy dog. 23 00:01:30,350 --> 00:01:36,950 OK, so how would we convert this into a ternary operation so that we can simplify this? 24 00:01:37,970 --> 00:01:41,660 Well, all we would have to do is take the conditional expression right here 25 00:01:44,690 --> 00:01:46,640 and then we just put a question mark. 26 00:01:50,280 --> 00:01:55,400 In fact, what we could do is just consider on this whole thing so we can use return values instead. 27 00:02:09,200 --> 00:02:09,710 Colin. 28 00:02:15,520 --> 00:02:15,840 OK. 29 00:02:17,470 --> 00:02:19,630 I'm thinking we're probably missing some. 30 00:02:23,230 --> 00:02:27,100 Oh, we're missing the end parentheses on the council blog. 31 00:02:29,620 --> 00:02:32,290 All right, so all of that fit right there. 32 00:02:34,810 --> 00:02:38,140 And to simplify this, just so we can read this a little bit cleaner. 33 00:02:40,890 --> 00:02:46,440 Happy, and we'll just say happy. 34 00:02:52,140 --> 00:02:52,370 To. 35 00:03:07,970 --> 00:03:08,700 OK, 36 00:03:12,300 --> 00:03:15,120 so it's really this simple. 37 00:03:16,190 --> 00:03:22,730 OK, this is the same as this we would happy, huh? 38 00:03:22,850 --> 00:03:24,520 Is it true? 39 00:03:24,540 --> 00:03:24,990 Yes. 40 00:03:24,990 --> 00:03:27,750 Happy if not not happy. 41 00:03:28,860 --> 00:03:32,850 Let's change this to sad and you'll see them both change. 42 00:03:33,860 --> 00:03:36,600 Not happy to back to happy. 43 00:03:38,780 --> 00:03:39,450 Very good. 44 00:03:39,860 --> 00:03:42,410 OK, so that's the ternary operator, 45 00:03:45,350 --> 00:03:54,830 ternary operator and it basically replaces simple if else statements and really cleans it up, as you 46 00:03:54,830 --> 00:03:55,290 can tell. 47 00:03:56,030 --> 00:03:58,630 So here's where your comparison is going to be. 48 00:03:59,450 --> 00:04:05,120 Here's what your true return is going to be, and here's what your false return is going to be. 49 00:04:05,720 --> 00:04:08,420 OK, and that's it for the ternary operator.