WEBVTT 00:00:00.844 --> 00:00:05.152 And we're back! This time, our program has the Winston object, 00:00:05.152 --> 00:00:10.020 but we're only displaying the age of Winston. That's because I wanna show 00:00:10.020 --> 00:00:13.719 you how we could change Winston's age. Because you know eventually, 00:00:13.719 --> 00:00:18.075 Winston has to get older. Let's remember what it would be like if we were 00:00:18.075 --> 00:00:22.695 just using simple variables. We have var winston age equals 19, and then if we 00:00:22.695 --> 00:00:27.088 wanted to change it, we would say winston age equals 20. 00:00:27.088 --> 00:00:31.275 and that would change the value stored in that variable. It's really really similar 00:00:31.275 --> 00:00:39.477 for object properties. We can just say winston dot age equals 20, and then we've changed 00:00:39.477 --> 00:00:43.609 the value stored in the age property of the Winston object. 00:00:43.609 --> 00:00:44.631 Cool. 00:00:44.631 --> 00:00:48.569 So let's see if that worked. We'll take our text command, put it below, 00:00:49.060 --> 00:00:54.020 change the y, tada! Winston got older. So easy. 00:00:54.543 --> 00:00:59.316 Um, okay, so now let's try, we were just adding one here 00:00:59.316 --> 00:01:07.309 let's do that more programatically. Let's say winston dot age equals winston dot age plus one. 00:01:07.309 --> 00:01:10.860 So what we're saying here is take the previous value of his age 00:01:10.860 --> 00:01:16.041 add one to it, and then store it in the age property. 00:01:16.903 --> 00:01:21.787 And that should just end up adding one to whatever the previous value was. Let's see. 00:01:22.956 --> 00:01:25.644 Display it, tada! He's 21. 00:01:25.644 --> 00:01:30.064 Getting getting so old. All right. Now, remember we have a shortcut for adding one 00:01:30.064 --> 00:01:36.803 to variables, and the same shortcut works with object properties so we can say winston dot age plus plus 00:01:37.556 --> 00:01:44.997 And let's see if that worked. Yup! And that really just did exactly the same thing as this line, 00:01:44.997 --> 00:01:49.144 it's just a shortcut, so that we don't have to type as much. 00:01:49.144 --> 00:01:53.330 Now if we look at all this, this really looks like the situation for a loop. 00:01:53.330 --> 00:01:57.792 We keep on using the same code over and over, and the only thing we're changing is we're adding one 00:01:57.792 --> 00:02:02.527 to his age, and we're changing the y position so it's on a different line. 00:02:03.018 --> 00:02:07.068 So, if we used a loop, it could be really easy to show him getting older and older and older 00:02:07.068 --> 00:02:13.497 and not have to use that much code. Let's say, we'll make a loop to show Winston getting to 40 years old. 00:02:13.497 --> 00:02:16.207 He doesn't wanna get any older than that because then he'd be wrinkly 00:02:16.257 --> 00:02:19.250 and we'd have to call him "Wrinkleston." [laugh] 00:02:19.250 --> 00:02:20.320 All right. 00:02:20.320 --> 00:02:27.498 So we'll do a while loop and we'll say while winston dot age is less than or equal to 40 00:02:27.498 --> 00:02:32.245 and then inside here, we're gonna display his age 00:02:32.245 --> 00:02:37.586 and we're going to add one to his age each time. 00:02:37.586 --> 00:02:42.108 Okay, that worked, but everything is piled on top of each other, so we need to change the y position 00:02:42.108 --> 00:02:53.250 each time. And we'll just do winston dot age times 20, um, minus 200, minus 300 00:02:53.250 --> 00:03:03.471 Okay! and we'll just minus 350. All right. That looks good. Let's delete the old stuff here. 00:03:03.471 --> 00:03:10.283 Tada! Now we can see Winston getting older and older, but not so old that he'll be a Wrinkleston. 00:03:10.283 --> 00:03:16.421 Okay. So, now we can see how to change age, we can also add additional information in the 00:03:16.421 --> 00:03:22.145 Winston object as he gets older. Like, maybe when he turns 30, he'll meet another programmer 00:03:22.145 --> 00:03:24.843 named Winnefer, and he'll marry her. 00:03:24.843 --> 00:03:28.979 And no, he's not just gonna marry her because she has such a great name. 00:03:28.979 --> 00:03:33.864 So what we can do is we can add a property by just saying winston dot, and then the new 00:03:33.864 --> 00:03:39.338 property key which will be wife, equals Winnefer. 00:03:39.338 --> 00:03:44.045 Great, but, we only want him to have this wife when he's at, you know, at a good marrying age 00:03:44.045 --> 00:03:53.138 so we'll say equals 30 and we'll go and move, move that inside here. 00:03:53.138 --> 00:03:57.759 Great. So now he has a wife, so, you know, they're happy, and then they have some kids 00:03:57.759 --> 00:04:04.204 a couple years later, so maybe when they're, uh, 32, we'll add some kids to the object 00:04:04.204 --> 00:04:08.198 to keep track of that. And they have twins, of course, cause they're very productive 00:04:08.198 --> 00:04:16.870 And Winston's twins will be named, uh, of course Winston Junior and Winstonia. 00:04:16.870 --> 00:04:21.851 Beautiful. That's a, that's a great family. Great set of names. 00:04:21.851 --> 00:04:25.395 And so you can see we can add new properties that are strings and arrays 00:04:25.395 --> 00:04:28.516 and anything we could've had in the original object. 00:04:28.516 --> 00:04:33.530 And so once this loop finishes, winston dot age will be 40, and winston will 00:04:33.530 --> 00:04:41.096 have a wife, who's Winnefer, and a twins, which is a set of er, which an array of two names. 00:04:41.096 --> 00:04:45.943 Huh. That's an awesome loop. But, hey, if you don't like how this story ends for Winston, 00:04:45.943 --> 00:04:50.178 you could always spin off this program and tell your own story of his future 00:04:50.178 --> 00:04:53.733 now that you know all about how to change object properties.