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

All Dots Aboard

Yay we can finally say we are ready to find both the starting dots and the ending dots. If you've just hit this page then you really should start from the first first video to actually get what's going on.

Video Transcript

00:00All right, so we left off at a point where we knew that we're between two and three and really the
00:05The last thing that's left for us is really we want to make sure that we actually
00:10Know also when we're completed now that shouldn't be too hard now that we know when we're starting when we're ending and we know
00:17When we're ending when we're flipping so if we do our get line again, just right before
00:23Just right well right exactly when we move into the safe as well
00:28We'll see that that should work. Oh, it's only in this scenario
00:31We don't need that subtraction because now we're in the safe zone already
00:34So we don't have to subtract the value to get back into the safe zone because we just entered into it
00:40Now if we ask ourselves the direction
00:44The direction should be it is important to us
00:47But we really would we'd want to be able to know that direction we would need to store that direction to make our lives easier
00:54now
00:55By the way, we only solved this for one direction. We didn't solve it to the other direction yet
01:01So we're gonna have to figure out a way to solve for the opposite direction as well in a second
01:05all right, but let's just make sure that this works for this to this scenario where if we're starting from 2 3
01:13Let's say we end it between 4 between 3 and 4 now
01:20Where's our trace? We're not getting that trace why because now our point is in that x so we have to start solving that x as well
01:29We have to solve that opposite if it's not the x so if it's not the x and by the way
01:35Also, as soon as we have that value as soon as our range is true as soon as we found the points
01:41We could leave our for loop. We don't need to continue in the for loop anymore
01:45But before we do that what we're going to do is we're just gonna add in also that scenario
01:49If it's y and not x so the question to y and not x would probably be very similar, right?
01:55So if I'm just gonna grab all this and let's see if we could just modify some of the code here
01:59Just to make it more friendly to our needs now
02:04Probably we don't create us the same variable twice
02:06So we could just go up here and just create those variables quickly. We're gonna have the num which is gonna be a number
02:12We're gonna have our range which is gonna be a number as well now
02:17We don't have to define a new number each time
02:20And a new range each time
02:23So so far we know that this area as far as we could see works
02:27Now and when we're looking into our code first of all, we still want to check between we still oh first of all this if
02:37Doesn't need that right? This is
02:39Added nothing so because that is always true, but that that messed up our if a little bit
02:44I think so we got rid of that
02:47All right, so first of all, we want to check if our point if our point x instead of y this time
02:53Equals the x of a current position and it equals the x of the next one
02:59And in that case, what do we want to do in that case?
03:03we want to take the range of the wise instead of the X's and
03:07We want to subtract the wise as well
03:10And we want to check if our range and our y correlate, right?
03:15So let's see if this one works this time around. So now that we have our x which is our first one duplicate definition
03:21Is never a good thing. So
03:23Let's copy that
03:27And that
03:29Run it one more time. All right. So first of all our between our two dots first two dots
03:33We sort that they work. Let's see if we'll get it also to work for our second up
03:37Still we're not getting what we need. Why is that?
03:40Things are not going the way we hoped right?
03:44So first of all, maybe because things are changing here. So let's maybe
03:48Before we even do all this. We're just going to grab this and right before let's just to make sure before even start looking for the issue
03:56Nope, we have no we have no solve yet. So let's see. How could we sort this out?
04:01So first of our first get line works perfectly our second get line just never finds the value probably
04:07So if we look at this, we're gonna find our issue. So first of all
04:12It's stopping at one
04:15And not at two. Why is it stopping at one and not a two and we have read the value of 4 13?
04:214 13 is fine
04:244 13 is that basically our value is between
04:29our
04:31Value is between that y equals 4 78 and y equals 2 so it should be between these two lines
04:38Unfortunately, our X is not coming back the way we would hope it would come back
04:42And if we look at our code just one more time just to see if there's anything we could do to adjust this to make this
04:48Right, and if we look at that value, we'll see first of all our dot x dot y is really the dot where we're currently
04:56Stopped and for some reason we're going one step further than where we thought it would be the safe spot
05:04So what I want to do is I want to make sure that whenever I'm stopping I
05:09Want to make sure that my dot goes to be in because I know that we're safe now
05:13I know that we're safe. So even before we call this get line
05:16I just want to make sure that my X and my Y are in the acceptable range
05:22So to do that, I'm just going to take my dot that X you can tell it dot that X you should be equal to
05:29math max
05:31The value of that line with divide by 2
05:36Well, here we go. So that line with divided by 2 and what else and
05:45The current value that you're at what that will give me is it's going to make sure that my value of my X could never be
05:51smaller than
05:532
05:54Or even if in the future it's going to be a different value. So it makes sure that we can't be smaller than that
05:58That sounds one direction. So hopefully let's see if this source our issue out now
06:03Now that we're going and we're taking a smaller number. Hopefully now is gonna
06:08Round up back to 2 which is exactly what it did. That's a good thing
06:12So now that it rounded up to 2 we would hope that it would find this combination, but it didn't
06:18So if we go back again into our code here, why didn't they get there?
06:24So first of all, it's going through the length minus 1 which is okay because it's going until here
06:30But because it's I is smaller than then it's actually going to stop here
06:36No, yeah
06:38Let's see. So if we just do your quick trace, I'm just gonna trace out no matter what I'm gonna no matter what just give
06:44You're a little tracer of the current dot that we're at. So actually it's put inside of that else statement
06:50Because that's where we're having issues
06:52And I'm just going to trace out that current dot that we're at right now just to see where it stops
06:56And if it goes all the way through which all the way through means one less than all the way through
07:01Alright, so first of all, it's not going through it. Oh, that's not too good. We're not even getting into this else statement
07:10Definitely not good and the reason is here again is because we're probably resetting just before say
07:17We're ready resetting in the add Bg. We're resetting everything
07:20So I'm just gonna make sure again is gonna be on the top there because it actually does matter probably
07:25Let's see this one more time
07:28And here we go now it's not resetting it
07:30But still we're not getting the value that we want, but at least we know that we're going through all the dots
07:35So at least we're taking a step further
07:38So we know that our dot is fine because x2 is perfectly fine and our x2 and y
07:45478 so y 478 should bring us a value
07:50well, our current dot is actually
07:54155 478 in other words, it should be between a
07:59place where our
08:01Current dot let's let's just look at this just for a second. Okay, let's just start this one or two
08:05Cuz this was that you don't really want to rush. Okay, so I'm starting
08:09You know, let me let me just slow this down. So so we could delete stuff that we don't care about
08:15Let's go back to that 24
08:20So it's a little bit slower run it again and this time this time around when it goes up
08:24I'm just gonna come here and clear all that because I don't care about the starting point right now and
08:30Back to our window. I'm just gonna turn it now and after I turn it
08:35I'm just gonna take that value and really try to analyze to try to find where is our application cracking?
08:40Where is it failing to deliver? So I'm just gonna copy this value
08:44So first of all already I see an issue here. Well, not really because these are the two
08:49These are the two points. Oh, there we go. So ready we see the issue
08:52This is the point that we actually care about that value didn't change
08:56so if we look at our code just one more time and
09:01That's because again we we updated it too late we updated it after we called to get line look more issues, right?
09:09Put it back up here
09:11So even though we created it we moved to all things around and never really got updated
09:15So and we could probably speed it up again now
09:19And really this is how you analyze this episode first of all is you know, look at your trace
09:24Slowly try to figure out what what's wrong? What's not panning out?
09:29All right. So we got our
09:31Our second chance going on here
09:34Here we go. And now we're getting the value that we hope to get so we got here that three four
09:38And we're really that's the value was between
09:42Three and four zero one two three four between these two values is our X to
09:48Y 400 so that that's brilliant now only problem is maybe we have a problem. So when we're turning backwards
09:53Let's see if we have a problem when we turn back when our number is actually bigger
09:57So we see yep, we have a problem in our numbers bigger. Why is there a problem here?
10:02318 is actually a good value. Oh here actually we do see it here between one and two. No, no, no problem
10:08We got the right value. So we don't have to adjust it if it's going upwards at least for now

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!