[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:10.95,0:00:16.24,Default,,0000,0000,0000,,Hello and welcome to 6.2 lab 3 let's go ahead and dive in! Open this file and your js Dialogue: 0,0:00:16.24,0:00:20.80,Default,,0000,0000,0000,,file like usual, and let's look at what we're going to do here. We are going to create a Dialogue: 0,0:00:20.80,0:00:25.98,Default,,0000,0000,0000,,function lab62_3 function and we are going to create two array variables this is were we Dialogue: 0,0:00:25.98,0:00:29.89,Default,,0000,0000,0000,,are going to deal with parallel arrays, and so you can just copy and paste this code in Dialogue: 0,0:00:29.89,0:00:34.15,Default,,0000,0000,0000,,here so you don't have to retype everything. Now one thing, let me just take a side step Dialogue: 0,0:00:34.15,0:00:37.74,Default,,0000,0000,0000,,for a moment and talk about parallel arrays. A lot of times when you are working Dialogue: 0,0:00:37.74,0:00:42.18,Default,,0000,0000,0000,,on an application you are not going to type it or hard code it in like this. A lot of times Dialogue: 0,0:00:42.18,0:00:46.49,Default,,0000,0000,0000,,the data you are going to receive is going to come from some other source like a Dialogue: 0,0:00:46.49,0:00:51.01,Default,,0000,0000,0000,,database that you are getting that information from or maybe a third party so you Dialogue: 0,0:00:51.01,0:00:54.14,Default,,0000,0000,0000,,are hitting a web service or something were you are pulling that data back. Dialogue: 0,0:00:54.14,0:00:58.05,Default,,0000,0000,0000,,Whenever you are working with data and parallel like this you just need to be Dialogue: 0,0:00:58.05,0:01:04.75,Default,,0000,0000,0000,,careful with your logic, for example I had my first student there in my names, Natasha Dialogue: 0,0:01:04.75,0:01:12.36,Default,,0000,0000,0000,,Peeks and her score is a 76, Boyd, he has a 99. We wouldn't want to mess that up Dialogue: 0,0:01:12.36,0:01:17.62,Default,,0000,0000,0000,,were Natasha now as a 99 and Boyd as a 76 or Natasha will be extremely happy Dialogue: 0,0:01:17.62,0:01:22.30,Default,,0000,0000,0000,,and Boyd extremely disappointed. So we want to make sure we work things correctly Dialogue: 0,0:01:22.30,0:01:27.18,Default,,0000,0000,0000,,when we are working with parallel data, in fact a lot of times what I'll do is if I am getting Dialogue: 0,0:01:27.18,0:01:34.14,Default,,0000,0000,0000,,this from a database I may lump it into 1 2 dimensional ray and that way I am hitting Dialogue: 0,0:01:34.14,0:01:38.82,Default,,0000,0000,0000,,one array and I am lumping that stuff together or I use a j son object where I have an Dialogue: 0,0:01:38.82,0:01:44.60,Default,,0000,0000,0000,,object of Boyd and he has a property of 99, that sort of thing. But sometimes you will Dialogue: 0,0:01:44.60,0:01:48.18,Default,,0000,0000,0000,,work with parallel arrays like this and I just want to go through this with you so you Dialogue: 0,0:01:48.18,0:01:53.92,Default,,0000,0000,0000,,understand how these are working. So we are going to have a variable and use Dialogue: 0,0:01:53.92,0:01:59.49,Default,,0000,0000,0000,,the get by ID to get are table. And then we are going to have a look looking for scores Dialogue: 0,0:01:59.49,0:02:04.21,Default,,0000,0000,0000,,88 or above. When we hit that, we are going to output the students name and table row Dialogue: 0,0:02:04.21,0:02:09.34,Default,,0000,0000,0000,,and I have an example of arrays you can click on here to see some information on it Dialogue: 0,0:02:09.34,0:02:16.64,Default,,0000,0000,0000,,so if you need to take a look at that feel free. Now let's just check the output here, and Dialogue: 0,0:02:16.64,0:02:23.67,Default,,0000,0000,0000,,the example I have, I am going to have all those names listed if they have 88 or Dialogue: 0,0:02:23.67,0:02:31.82,Default,,0000,0000,0000,,above. So let's take a look at how we are going to do this, so in our html in our output Dialogue: 0,0:02:31.82,0:02:37.27,Default,,0000,0000,0000,,div I have a table were I have an ID of outputTable so I can grab it, the class of the Dialogue: 0,0:02:37.27,0:02:42.20,Default,,0000,0000,0000,,contentTable is just stylistic, and then I created a table row with two headers with the Dialogue: 0,0:02:42.20,0:02:47.08,Default,,0000,0000,0000,,name and exam score so I can add rows and put them in our columns appropriately Dialogue: 0,0:02:47.08,0:02:53.39,Default,,0000,0000,0000,,so then in my function I have a scores variable, and I have a names variable with the Dialogue: 0,0:02:53.39,0:03:00.05,Default,,0000,0000,0000,,appropriate data. Then in my output variable I simply said go into my document get my Dialogue: 0,0:03:00.05,0:03:07.17,Default,,0000,0000,0000,,element with an ID with outputTable. So I grabbed that html element of outputTable, that Dialogue: 0,0:03:07.17,0:03:11.62,Default,,0000,0000,0000,,table tag and dumped it in my output variable so now I have a hold on that. And then I Dialogue: 0,0:03:11.62,0:03:17.26,Default,,0000,0000,0000,,am just doing a loop. So in my loop here I am looping through my scores, starting at 76 Dialogue: 0,0:03:17.26,0:03:21.70,Default,,0000,0000,0000,,and going all the way through to 79 just a normal for loop and I am just testing it Dialogue: 0,0:03:21.70,0:03:28.62,Default,,0000,0000,0000,,is my score greater than or equal to 88? if it is, then I am saying ok I want to compound Dialogue: 0,0:03:28.62,0:03:34.98,Default,,0000,0000,0000,,add to my table, a table with a table row with a table data cell with names and Dialogue: 0,0:03:34.98,0:03:38.95,Default,,0000,0000,0000,,notice I am using, I am hitting, even though I am looping over my scores array Dialogue: 0,0:03:38.95,0:03:43.75,Default,,0000,0000,0000,,I am hitting my names array and using the same i variable to make sure I pull out Dialogue: 0,0:03:43.75,0:03:50.19,Default,,0000,0000,0000,,the exact same. So if I am pulling out 99 here I want to pull out Boyd, so that is why Dialogue: 0,0:03:50.19,0:03:55.39,Default,,0000,0000,0000,,I am using my names bracket notation there and then I am pulling out the scores with Dialogue: 0,0:03:55.39,0:04:01.33,Default,,0000,0000,0000,,the appropriate html tag intersperse for my cells. So this example is just to show you Dialogue: 0,0:04:01.33,0:04:05.20,Default,,0000,0000,0000,,how you can go through loop through one array and hit a parallel array at the Dialogue: 0,0:04:05.20,0:04:09.22,Default,,0000,0000,0000,,same time, you just got to be careful you are doing it correctly so that you pull out Dialogue: 0,0:04:09.22,0:04:14.33,Default,,0000,0000,0000,,the appropriate information so like in my scenario Boyd is getting the right score Dialogue: 0,0:04:14.33,0:04:20.13,Default,,0000,0000,0000,,and not Natasha who did not earn her 99 so if you do that correctly you will get that Dialogue: 0,0:04:20.13,0:04:24.76,Default,,0000,0000,0000,,table. If you have any questions let me know and happy coding!