02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

From Rational to Boolean

All the operators we worked with so far returned in our trace panel a value of true or false. In this video we'll see that connection of our operators results in the Boolean data type as we explore storing our operator values into Boolean variables for reference.

We know how Boolean variables work with equality operators. Now we'll see how rational operators can be used in Boolean form. For example let's declare a few variables using var and assign values to them. Let the values be: a=5, b=10, c=b. Now we can compare these variables with one another and assign this comparison to another variable of type Boolean. Here's an example to understand this:

var isTrue: Boolean = (c<=a);

Here c<=a is what we want to find and we can find it directly. But if we want to change from rational to Boolean, we can use the above declaration.

So now the new Boolean variable is isTrue and we'll now work with this variable wherever we need to compare c<=a. The answer is still either true or false, depending upon the values: here the answer would be false as it does not satisfy the values of a and c. The advantage of changing from rational to Boolean is that we need not write the equality every time when we want to compare. We can just write trace(isTrue) to check whether the equation is satisfied or not. Here the equation is small and you may not find any difficulty, but when we deal with big equations, then this is definitely one of the best options to be considered.

Video Transcript

00:01So I'll have the last video we were working with Booleans without calling them Booleans all these expressions that we've worked here
00:09Here are Booleans and as they are Booleans we could have assigned these values and save them into a Boolean value
00:17Let's see how we would do that
00:18so for example if we're just grab one of these traces and I get rid of everything but one of the equations and
00:25I'm going to create her a new variable which will be is
00:29true
00:30Boolean which would be a Boolean value and let's just get rid of this extra bracket that we don't need round bracket
00:37So we're basically we created a Boolean here, which we could use later on
00:42But if we wanted to we could write ahead trace out our is true
00:47Hope is our is true Boolean and our is true Boolean will return false as we expected
00:57So this is this value that we created could be assigned into a Boolean and we could use it later on
01:04if we would need to and
01:06The same is true to all the rest
01:08So I instead of running through every single one of them step by step. Let's just really do them really quickly
01:13So if I just run through this quickly, I just take my is true again, and I don't need to create a new variable
01:20I'm just going to reuse the variable that I've had. I don't have to redefine it
01:24I just delete the bracket here because we don't want an extra bracket
01:28Whereas changing the value of is true right now
01:31So if we trace out our is true the value that should come out is true, and that's exactly what happened
01:41So now the code might start looking a bit messy
01:44But it's completely valid now if you were concerned you could always add a bracket just for the sake of making it look nicer
01:52It would it wouldn't change anything
01:55Okay, so it's not really needed flash doesn't need that bracket. It's smart enough to realize what you're wanting from it
02:02But if it makes it easier and cleaner for you to type this way then just do that
02:07Okay, so let's see for example another option
02:12And we'll just run it through quickly again, so I'm just going to copy what I need out of here
02:17You know and let me just assign it in the same way. Just so everything will look similar and
02:24We're going to trace our same variable right after we define it
02:29All right, and let's continue on let's just do it to all of them
02:37so is true equal and we want to make sure that we get rid of that and
02:54less item
02:56Would be this one. It's true
02:59equal equals up only equal made that mistake
03:03Don't make it. Okay, so let's run it and just see that everything still works and
03:15if we run through our application step-by-step, we're going to see that
03:19That this is should come out as true
03:22Which is the false which is the first one and it comes out as false the second should come out as true
03:27The third is false the fourth is true and the last item should come back is true as well
03:33And we could see that everything is still working the way we expected it to work
03:37Now the next thing I want to do I want to just block out all this code that we just created here
03:43Because I want to talk about another topic
03:45So I'm going to agree. I'm going to block out the whole group with a blocking comment. So that will be slash
03:51star and
03:53We're going to say where we want to end it
03:54Which is just before a function ends and we want to end our block right here
03:58And you can see that our code comes back and turns to be dark again black again showing us that all the area
04:05That's gray has been dimmed out now
04:09Excellent, so let's just have a better view here
04:13We've talked about
04:15assigning data into Booleans and the last thing I want to talk about regarding rational operators is that
04:22You have more options with rational operators such as
04:26You could compare more than one time and when you compare more than one time
04:33it's not exactly a
04:36Logical thing to do but you could and because you could it you could do it
04:40Then we want to show it and kind of explain what actually is happening. So if we would ask is a
04:45smaller than B smaller than C
04:49What value would you?
04:51expect
04:53For it to come back and what we mainly want to focus on is one is you really don't want to do this in flash
04:59We're going to see different ways of working within flash than this way
05:05But if you do do or want to work in this way
05:08Then the values you're going to get back are going to be somewhat confusing
05:12Because a is smaller than B. That is true, but B is not smaller than C. So why is that coming back as true?
05:20Okay, so don't even attempt to work in this way because it's not going to be rational

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!