02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous Video
Chapter is concluded.Next is

Loops Homework

Time for some homework when you complete it feel free to send it to us so we can review it! By the way Carole already sent us her homework long ago and did an amazing job.

Video Transcript

00:00That's really all I have to say about loops, and really the only question I have for you is how comfortable do you feel with loops now after watching the videos, doing the exam, and this session together?
00:28Could you repeat that? The function with parameters, what parameters? Oh, you mean like for the function parameters?
00:36Correct, correct.
00:37Oh, that's fair enough, and what I can give you as a task for homework, and I want you to do this on Facebook, is take this function, write it down right now because I'm not uploading it onto the web.
00:48You know what, let me upload it just for you. So I'm going to upload it in the end of the class. I'll just upload it now onto the chat room so you can have it because I'm going to add this into our bonus DVD.
00:57And it's not going to go on the site. What I want you to do is take this for loop, this power function, and create something that's less dynamic. I want you to create a powers of 3.
01:07Okay, it's going to be 3 powered 5. So I want you to create 3 powered 5 without a function. Just create a loop without all these variables, right? All these variables are confusing.
01:15Create a for loop that just returns to me the value of 3 powered 5 in the power of 5. Okay?
01:253 to the power of 5, okay.
01:27Exactly. And you don't even have to copy this even better off that you won't. Just create that function.
01:32Drop everything. Use numbers. Only variable you need is your i to know how many times you have to do. But all the rest, just use straight on, you could use whatever you need to make it happen. You don't have to use all these variables.
01:46These variables just made it dynamic. And after you're done with that, then come back to this function. And I actually want you, I'm not even going to upload the source value because I don't want you to cheat on this one.
01:58Create that for loop. After you create it, just put it on our Facebook, our community, and then I'll paste to you this function. And then you tell me how this function works after that. Okay?
02:08Yeah, no functions, nothing. All you need is probably a variable to hold your information and a variable for your i to count how many times you're doing it. But that's all the variables that you're going to have. Okay?
02:34And you don't have to put in a function. Don't put in a function. All I want is your code when you're going to send it to me is going to be basically, it's going to be 2 lines or 3 lines more accurately.
02:46Now, I wanted to cover one more thing because I certainly had issues with that. Don't forget that an open and closing bracket is really important. These open and closing brackets tell us where our block of code starts and where it ends.
03:00If I get rid of these brackets, I'm just going to copy this and just make one more loop. Go right here at the top. And this is going to end our topic today.
03:11So if I have your 4 sometimes a, well, let's just have your trace. Trace, echo. Alright, so trace, echo. It's going to be i is going to run from 0 as long as i is smaller than 1. And then it's going to grow.
03:29So it's going to be a very, very easy loop, right? How many times is this loop going to run? Beautiful. Now, if I add here another trace, but I'm going to add this trace instead of inside of this loop, I'm going to add it in line 5.
03:44And when I add it into line 5, I want to ask you a question. How many times will this trace echo happen? Until this area. How many times would echo happen when we reach line 7? Right, and combined it would happen 2 times, right?
04:03Now, what happened if I change this to 10? Beautiful. So 11 times in total. Now, if I take this closing bracket and I move it here to line 6, how many times in total? 20 times.
04:28Now, what would happen if I delete now the opening bracket and the closing bracket? That's the harder part. Well, our for loop is still going down. Let me answer that just quickly.
04:49Whenever I, if I don't have an opening and closing bracket, it's the exact same thing as with an if statement. If I had an if statement that had here some sort of condition and I open and close a bracket and I did something in here and another sign in here and there's something here.
05:04Oh, that's great. But if I remove that brackets, what would happen? Only line 8 would be part of my if statement. Why? Because that this line is kind of like it's called an inline line.
05:16It's part of, it's part of my, it's part of my if because the if doesn't have a range. As soon as my if doesn't have a range, it has a range of one line. And that's also, by the way, it would run, it would run that one line.
05:33It would actually run still 10 times, but this line 5 and only run once, right? So this would still run 10 times and this would run only once. Exactly. And that's the importance of these brackets.
05:48So the rules of brackets don't change. It's the same rules for for loops, it's the same for if statements. It's even the same thing for functions in a way because if I didn't, well, you're not allowed to not put a bracket.
05:59But if in theory you were allowed not to put these opening and closing brackets, then in theory, your answer would be that everything would be in one line. But you can't do that. You could, and that's why also, by the way, you could also if you wanted to, for example, I'm just going to wrap this up.
06:17You could also if you wanted to, you could take a variable object, we talked about objects, right? So I could create an object and we said we could create it with the opening and closing brackets. And we said also that we could add parameters, we could add your variables, right?
06:29We could, or you want, we said we want to give them their formal name, their formal name was properties. So we could put their properties, all these names are interchangeable, they're all fine. And I could put here a key, and I could put a value.
06:41And then I could put a comma, and I could do another key. So I could be your key number two, and then a value that we know we covered that in objects. But what would happen if I would break the line right here? Would flash and think that my object is completed?
06:56No, why not? Because it knows that it's not over until this curly until this closing curly bracket happens.
07:04Okay, and the same is true with for loop. So the opening curly bracket, tell it basically tells flash, this for loop is not over until we you meet the next closing bracket. So even if my closing bracket was down here, and all the formatting was all messed up, it really doesn't matter.
07:19Because that for loop contains everything that's inside in a great way. And always remember this command comma, if you're on a Mac, selects everything. And if you're not on a Mac, then I don't know if it's like shift or out or whatever the key is called. And, and it will highlight everything inside of that area. It's so useful. So whatever inside of a loop, you have that open bracket, even if you have all these paddings, ignore the paddings, just look at your look at where is my area, okay, all this area is inside of my loop. That's what it told me. Okay.
07:47And if you don't have the opening closing, it's always one line. Okay, if you don't have if you don't, okay, the answer to that is if you didn't put a curly bracket, imagine that flash automatically puts it in it automatically puts it in doesn't change anything in your for loop.
08:15So your for loop is still going to run 10 times. If the brackets, oh, well, well, yeah, it definitely does. But the answer to that is, there is a there is an ending bracket. This is your ending bracket. Why is this your ending bracket? Because he didn't use a he didn't use a curly bracket. Same is true with if statements. So this is your ending bracket. So as soon as it reaches here, it goes back up to the top and it goes back up and it goes back up as long as this condition is met.
08:56As soon as that is done, then it goes right after that, which is basically line seven. So whenever this for loop is done, which will run 10 times in the scenario, then it's going to go to line seven. Okay, and the exact same thing, which no, right, it would be easier, it would be easier to see it if I did this, but I didn't want to make it easier, I wanted to make it harder for you on the exam.
09:18And I deliberately I'm tricking in the exams, the exams are really, really hard. If you think the loops part one is hard, the exams, the exams of loop are two are 10 times harder. If you get 40, if you get 40, 50, you're ready. No loops. And deliberately, I made really hard questions because it challenges you. It challenges you and it forces you to start thinking about how does these stuff work? Because I don't want I don't want the I just don't want the questions.
09:44Fantastic. No, no, no worries at all. What I wanted to just wanted to add in and say and say is that on all the exams on the site, it's true. Obviously, every hour that goes by, I make the exams harder. And deliberately, I'm making them harder and harder because I want you to challenge yourself more and more. Deliberately, the first exams are really easy, because I obviously don't want to scare you off in the beginning.
10:20But, but really, the key in the exams now is that even if I don't teach it in that specific course, I'm putting their things that to trick you from all of the developer basics.
10:32So, for example, the brackets, we didn't really talk about it too much inside of the of the loops, but we talked about it in the if statements and and deliberately I'm adding more and more of the and these these trick questions.
10:42I don't put all the mystery questions, but deliberately we're putting these trick questions inside to challenge you and make sure that you remember the stuff that we've learned before. Absolutely. Absolutely. Absolutely. And one of this challenges also, you know, and let me let me add just that just to make you feel more comfortable.
11:54Although if we look at the, you know, I'm just I'm just putting our site in here just for a second. It's before our redo, but hopefully we're gonna make that redo before the DVD comes out.
12:02So, by the way, when coding basics one and then I got the score 96 in it, I think I really got the score 96 and I didn't get a perfect hundred. Same for the first coding basics. So even though I wrote the questions myself, I've made mistakes.
12:16Well, maybe I didn't get 80, but that was because I was testing things out. But the point of it is, is that a perfect score is not always mandatory. But as long as you get above 80, that means you know the topics.
12:27Obviously, if you have a specific question or a pattern or question that you're noticing that you're always filling in it, or more importantly, when you go inside of a specific course and you see that a specific topic, you're just not doing well. And when you when you check the filtering after the exam, and even if you get 80 BC, one of the videos or two of the videos have you have a slow score in them, then you know, you need to refresh on that.
12:46But you don't have to you don't have to aim for a perfect score. Because a lot of times some definitely. No, absolutely. And you even if you're not noticing it, like you were talking to me that you're telling me that you were reading an article about JavaScript and you were getting what they were talking about.
13:23You're you knew you knew the code, even though we didn't learn JavaScript, you knew the code. And that's exactly absolutely. And that's our goal. Absolutely. And I'll add to that. And I'll just give you this. I think that's where we have we have our Facebook community and we'll have more communities that that's what it's going to be for.
14:23I don't want to I don't want to make the I don't want to make the courses more complex. We're learning a lot of stuff in those courses. And some people just don't like doing exercises. But I don't I don't. But the point of it is really, I want people to engage. I want people to interact with each other to ask questions to challenge things.
14:39One of the things I wanted to say, to connect to what you're saying, every single language that exists, from the stuff that we're learning in the developer basics, you could leverage the knowledge that you've made in it.
14:51And you can understand things in every single language. There's a lot of different ways that it's that it looks like there's a lot of different ways to write it down. There's, there's a few different philosophies in programming, but the developer basics covers basically things that cover anything related to programming.
15:07Now, the deeper we go in courses that are out of the developer basics, some of them are going to be related to specific genres of development. While you like some languages lend themselves more to object oriented programming versus others. So that the more we talk about object oriented programming, the more we're going to exclude ourselves from different from some languages.
15:28And also different styles of development. So some pro some programming languages are more about planning ahead as much as you can. And some programming languages are more about doing it dynamically and figuring out as you're going or as we call it agile development.
15:43So we're going to look at all this stuff at the deeper we go and the more hours you jump into later on after the developer basics in other releases in our site, everything fla.com, which is my last commercial for this hour. So I hope this helps.
15:56And your homework and your homework and your homework is to create the create a powers loop. Okay. And when you're done with that, I'll give you another piece of homework. You don't have to run and do the loops part two as quickly as possible because loops for two could be a little bit hard. So let's give you like two, three exercises.
16:39And so let me just say this just so for the sake of the people that are listening in and they're not going to be part of this personal conversation that we're having on Facebook. A few tasks that you could do one I want you to create for your to the members and then at the day, I want you to create a function that does powers like we did right now.
16:55I want you to create a function that finds the smallest number in an array. And I want to create a function that creates the biggest number in an array. Okay, so these are three exercises that I would like you to do.
17:06Before you move on to the part two because they integrate everything we learned so far. Okay. Oh, no problem. No problem. Have a good night and good luck. Okay, bye bye.

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!