Bill Rosener: Well, this is Dr. Bill. Welcome back in this video you'll be learning about loops in both Javascript and Php. As we create the same application once for the client on Javascript. Once on the server using Php, let's go ahead and take a look at what you learned how to create.
Bill Rosener: We're going to enter a value in here. This is just an image. I'll show you a working example in a second. You've got to get do 5 things. I'm going to get you some code, too, on the 1st one that does 3 of these things. But I'm going to see. I think you guys haven't got you get you started. I think you should be able to finish the rest. So if I enter 6, I'm going to print the numbers and increase in order from one to 6.
Bill Rosener: Then I'm going to print the numbers in decreasing order. From 6 to one. I'll print out the even numbers between here I'll create a square with 6 rows, 6 columns, and then we'll create a multiplication table, one to 6, and so one times that number, and then the result. There.
Bill Rosener: then, we're going to do the exact same thing in a Php. And, for example, by 106 increasing, decreasing the numbers create a square with that many rows and columns, and then the multiplication table. Okay? So those were just images. Actually, before I forget. Here, I'm going to give you some Javascript code right here. This is an image format.
Bill Rosener: So you'll still have to type this in
Bill Rosener: and then I'll type it in. But you're gonna have to make a few changes to it. This will get you started. And then here also is some Php code which you can use to get started.
Bill Rosener: Okay, now let's go ahead and take a look at
Bill Rosener: like a real work. Real working version. Here, here's that assignment 9 Javascript. We'll start off with that. So if I enter in a 6. If I hit display results, I'm gonna see. I'm gonna get the increase in
Bill Rosener: numbers from one to 6 decreasing multiplication table. If I was to put 10.
Bill Rosener: I'm going to get numbers and increase in order from one to that value, decreasing in a multiplication table again, going up to one to 10 times 10. So I'm going to give you the code for this. Then, again, you are going to
Bill Rosener: haven't given you that code. I think you'll easily figure this out, and then this shouldn't be too hard, either, creating a square. So
Bill Rosener: same number of rows and columns as this value entered here.
Bill Rosener: and then eventually we'll go ahead and do the exact same thing, using a Php. If I enter Essa 8,
Bill Rosener: we're going to go ahead and put the numbers increase in order decrease in, create a square, 8 rows, 8 columns, and then the multiplication table. In this case, one to 8.
Bill Rosener: Okay, well, now that we know what we want to do. Let's go ahead and I get started. So the very 1st step I'm going to do is open up an editor. I'm going to use visual studio code, and I'm just going to grab some code here.
Bill Rosener: copy it and come up here to file new text file and paste.
Bill Rosener: Okay, let me go ahead and explain this code here. So the very top here I've got HTML, hypertext markup language. I've got starting my head start in the title. I'm going to start my script. It's going to be a display results.
Bill Rosener: So maybe I should come on down here. Here is the form.
Bill Rosener: Go ahead and put put your name here, and I'll go ahead and put my name while I'm right here in.
Bill Rosener: So the form is going to have when I press on, display results. It's gonna look for a function called display results. That was a function. Actually, I can see it's right up here still. And then we're gonna have a text area where we display the information there.
Bill Rosener: So, taking a look here, what's going on here? 1st of all, I'm going to make sure the number entered is an integer, or it's actually, if it's a number, if this is stands for is not a number
Bill Rosener: at which point I would have a little air message pop up. But if it is a number I'm going to go ahead and continue.
Bill Rosener: So. What I'm going to be doing is storing information in something called temp string. I'm going to sign it the null value, and you're going to see. I just keep adding to it here, I'm going to say temp string is
Bill Rosener: what was in temp string, plus increasing order, writing it right back to itself. So you can see I just kind of keep building this temp string. Keep adding to it. Finally, the last step I'm going to do is take what's in temp, string and store it in form. One results. Here's form one results, and that's where the information will be placed. Take a look at the for loop. Here. Here is a for loop right here. Here's the syntax.
Bill Rosener: So it's going to start. In this case, index equal one while index is less than let's say we entered 6. Well, index is less than or equal. 6. The plus plus is going to increment it.
Bill Rosener: I'm then going to say, Okay, temp string is whatever is in temp string concatenated with one in a space and 2 in a space, and 3 in a space, etc. There.
Bill Rosener: okay, let's go ahead and save this.
Bill Rosener: and we'll just go ahead and take a look at it. This is going to be assignment 9
Bill Rosener: dot dash javascript, dot HTML, make sure you get the dot. HTML extension there. Assignment 9. Dash, Javascript.
Bill Rosener: Not a smell.
Bill Rosener: And here's a little bit larger. Okay, since I and I'm in visual studio code. I can just right click open and default Browser.
Bill Rosener: And here it is. I'll put a value.
Bill Rosener: And sure enough, that code is working. So I'm gonna give you some code here to get you going. And then again, you're gonna modify that to display just even numbers. And then this little square.
Bill Rosener: Okay, now, moving on, we're gonna do this exact same thing in a Php, so I'm gonna come right up here to file new text file.
Bill Rosener: go ahead and copy some code.
Bill Rosener: hey, set.
Bill Rosener: and I'll go ahead and delete that little space at the top. So in Php the angle bracket question, Mark Php. Is going to start my php.
Bill Rosener: this question, mark angle bracket is going to stop the Php code.
Bill Rosener: I'm going to have a little function just to test in the input I'm going to be passing that maximum values. I can see I've set initially to 5.
Bill Rosener: But I'm gonna allow the user to change that. But I keep passing that because this is going to be calling itself. If I come down here the Php self, it calls itself over and over.
Bill Rosener: So take a look almost the exact same thing here, the little difference there. Variables
Bill Rosener: and Php start with a dollar sign. So I'm going to set temp string equals to the null string. I've got my little loop here, I'm going to say index equal one while index is less than say, 6.
Bill Rosener: I'm gonna be incrementing it. And I'm just going to be saying here, I'm gonna say, index is equal to
Bill Rosener: whatever was in there.
Bill Rosener: And here the concatenation is that little period. So I'm gonna simply say, like one in a space, 2 in a space, 3 in a space, etc. there.
Bill Rosener: Okay, here. I've incremented it by one. Here I am decrementing it by one. And just to kind of let you know a little bit here
Bill Rosener: rather than saying index plus plus, I could have actually said equals index plus one, okay.
Bill Rosener: or the same thing here with the decrement. So anyway, that's kinda hopefully getting you going well on that printing the even and the odd numbers there.
Bill Rosener: we're actually printing increments of 2.
Bill Rosener: Okay? And so I keep adding, I keep building this temp string. I keep adding to it. I keep adding to it, and what you're going to find is, after this is all done. I've got this long string, and now what's going to happen is, I'm going to say, echo, temp, string, and that's going to go ahead and display that within that text box texting. Okay, let me go ahead and save this, and we come right up here to file, save as
Bill Rosener: yeah, save a little time here. Just I'll delete the students
Bill Rosener: and assignment 9. Dash. Php, dot. Espn.
Bill Rosener: yeah, I'll tell you what. Maybe I'm just to make sure I'm I'm gonna go ahead and put my name here.
Bill Rosener: Okay, okay, so I'm ready to save this file, so
Bill Rosener: I came over here. Take a look at it. I can now see I'm saving everything on the desktop in a folder called temp. I can see we. I initially showed you the student version. Now, I just got done creating these 2 files.
Bill Rosener: The HTML, I can view that locally on the client. I don't have to upload that. You will eventually upload that
Bill Rosener: to get credit to your website. But let me come along and hit refresh.
Bill Rosener: And I'm now going to highlight these 2 files.
Bill Rosener: These are the 1st ones had students. This do not. I'm gonna go ahead and upload.
Bill Rosener: Okay. Now, I'm gonna come along.
Bill Rosener: Come over here, take a look.
Bill Rosener: I'll tell you what may just strip this off. Might be a little quicker here.
Bill Rosener: Okay, and here was, that's the students. Here's the non when it's got done doing, which is exactly the same thing. I put a value in here and display results.
Bill Rosener: And then the same thing here with this assignment. 9 Esp. Put a value in here. And again, here's why
Bill Rosener: you can see why we had to pass that Max value when it calls itself. For example, it was 5. I put 8, or maybe I could put
Bill Rosener: 7 and hit display results there.
Bill Rosener: Well, hopefully in this video you learned a little bit about for loops
Bill Rosener: in both Javascript and in Php, and again, maybe start off taking a look at some of the code here and type that in, and then see if you got to challenge yourself. See if you can get some of these missing elements into the final your final code there, anyway, I'll catch you next. Video. Thanks a lot. Bye.