Yo, what’s going on people? You’re watching JavaScript for beginners task 19 and in this video I just wanted to go through a practical precedent of willing to use a loop in JavaScript. All privilege, then guys. So, as “youre seeing”, I’m back in the index folder right here and I’ve got some associations numbered from 0 to 5 there. Now I’ve started at 0 because usually javascript is a zero based usage, meaning that when we use arrays or index variables, as we’ve seen in curves, we often start at 0. So I thought it reaches smell to start at 0 for these associates. As well so what I want to do is show you an example of how loops in JavaScript can cycle through parts on your webpage and change them in HTML all right. So let’s climb over to this test file, which is our a tie-up table, and I don’t need to pay too much attention to the code that are right here. I’m just demonstrate you how loop can work with a web page. We’re going to cover all of this additional code later in this playlist. So let’s is the beginning with a variable announced associations, and this is going to be array which is going to hold all of the linchpin labels on the page. So we’ll use the get element by label list to do that and we’re going to go up to our 8x. So now it’s going to accumulate all the anti connects in an regalium for us and again don’t worry about arrays. More I’m going to cover those last-minute now. We’ll time our for loop and the components we need remember are the initializer the index variable and we’ll establish that to be I equals 0. Then we want the loop to continue for as long as I is less than relations portion. So that meant that, for as long as I is less than the number of links on the page, we’ll continue to do this. So then it will catch. All of the links and then finally we want to increment I by 1 each time around. Alright, so let’s do the code last-minute so, each time around, we have I as a specific number, if that’s off 0, then 1 and 2 and 3. Now we can use that numeral to grab all of a specific link in this array, so that’s what we’re going to do. So we’ll, say associates which is the array, and then we want the eighth number of that last-minute array. So we’ll start at zero. That would first time round be zero, placed era, rounded one then two etc. So, each time I is going at one and that’s going to get us the first and the second largest, then the third link etc, and each time we iterate through this curve. We want to do something to those joins or that link, and we’re going to give it a class call each time. So we’re going to give the class word to be linked. Then we’re going to concatenate whatever I is so that will be linked 0, then relation 1, then relate etc. Going through and again don’t worry too much about this code here in this code. Here I’m going to show you all of this later in the playlist. This is just an example of how we can use loops-the-loops okay, so let’s save that off and refresh over here and, as you can see now it’s looped through each tie-up in a HTML document and it’s given one each sorry. Each anchor call a class of connect 0, then attach 1, then link to, and that’s this bit right here. So we’ve achieved what we set out to do so that’s how we can use loops-the-loops to cycle through points on a sheet and do things with them, and this is just one of many different things we can do with those things. If “were trying to”, we could animate those connections or conversion the mode qualities. Whatever you want to do, you can do that, so I hope this has induced smell. I just wanted to give you an example of where we’d use loops-the-loops and if you have any questions about this whatsoever, feel free to remark down below I’ll answer all of those. Otherwise, if you experience these videos, delight like share subscribe, and I’ll see you guys in the next one . .
Related posts
-
C# Tutorial For Beginners – Learn C# Basics in 1 Hour
Hi! Thank you for taking my C# tutorial for beginners. Let me quickly give you an... -
WordPress Tutorial: Build Your Affiliate Marketing Sales Funnel
Hi Kevin Barham now and in this shorttutorial I’m gonna show you how to build an... -
Python OOP Tutorial 1: Classes and Instances
Hey, everybody. How’s going in this streaks of videos? We’ll be learning how to create and...