 Well, it's that time of the week again. It's time for Chit Chat Across the Pond Episode Number 451 for August 17, 2016. And I'm your host, Allison Sheridan. And this week, our guest is Bart Bouchotte's back with the second of two videos that we're trying to create to show you the solution to the JavaScript challenges. How are you doing today, Bart? I am doing just fine. All right. This whole video thing has worked out pretty well. Yeah, I'm hoping that we do a little more chatter for the audio-only audience to make sure that's still just as valuable as it was before. But if you want to see the video, that'll be up over at podfee.com when we're done recording. So let's see, where did we leave off last time? OK, so we did four out of the five we just did and finished. So they were easy. We did, well, they weren't easy, but we did them. They were all done. And then we made a start on Challenge 5, which is, like, it's worth, like, quadruple, quintuple, many, many times the credit of the other ones. It's a big one. So this is the complex number problem, right? So essentially, it's broken into many sub-steps. But essentially, what we're trying to do here is we're trying to create our own custom data type to represent complex numbers and to imbue that data type we're creating with all the different things we want to be able to do to complex numbers. So so far, we have written a simple constructor, which stores our complex number as two data points. This.onerscore real and this.onerscore imaginary, representing the real and the imaginary part of the complex number. We also then wrote some accessor methods to access real and imaginary. So we call them real and imaginary because we're very unimaginative. And then we wrote a function called toString, where we put in a whole bunch of ifs and else's to assemble our output in the prettiest possible way. If it was a, if the only thing given, if it was like minus one i and no real, minus one imaginary parts and no real parts, don't print out zero, just print blankness followed by minus one i and all this kind of, lots of special cases to make it look like a human would write it, because we wouldn't write zero plus zero i or zero plus one i or something, we'd write i, we wouldn't, so it's trying to be as human friendly as possible or toString function, which is why I got quite well. One little piece in here, when we were talking about it last time, I expressed confusion as to why sometimes there's an if statement that doesn't have an else statement. And Joe Romansky wrote to me with another one of her wonderful missives, but a piece of that was explaining why sometimes there's an if without an else. And the example she gave was, if you win the lottery, buy me a car. There doesn't have to be an else, there's an implied else that is, else don't. And I love that because that is going to, as soon as I saw these if then statements that analogy came back to me and I think that's really gonna help me understand that yeah, sometimes if there's nothing else to do, just don't. Yeah, just nothing, just yeah. They can hang there, you can leave an if statement hanging. Yep. Okay, and then the last thing we had done was I had put some test, some sample code to test the prototype written so far to make sure it printed out everything beautifully. And then we called it a day. So that was part five, was that? So now we're on to part two. I think I ended that with, are you kidding me? There's that many more steps. I hope that can re-listen to me say that. Yeah, because so far our complex number, we can put values in and we can see them. But that's not particularly useful if we wanted to use this complex number type to do some sort of, I don't know, physics-y stuff involving magnetic fields and electric fields and stuff. We'd need more, right? This is a good start, but they're still pretty dumb complex numbers. So we need to inject some more intelligence into them. And the first thing we're going to inject into them is we're going to make it easier to put the values in. So instead of having to say var my new number equal or my number equals new complex number and then my number dot real and give it a value and then my number dot complex, r dot imaginary and give it a value. That's like three steps just to get a number in that. That seems cumbersome. So the first thing I'm going to write is a function called parse, which is going to expect an input in a very generous number of different ways and just do the right thing. So... Parse isn't one of those secret words, right? It's not a secret word, but it's a word you'll see used a lot by computer scientists. It just means interprets. It's not sacred in any way. It is not sacred in any way. Okay. It doesn't really have information about it. Yeah, to parse something means to understand it. So we're writing a function whose two strings job is to take what's inside and push it out. And parse is very much the opposite. It's like take any sort of a sensible way of describing your imaginary number and suck it in. Hmm, okay. So it probably comes as no surprise. It's going to be full of lots of if else statements where we are interested in basically saying, well, if you're this type, then we'll do this with you. If you're that type, we'll do that to you. So I say that your function should be able to accept all the following. So either you can parse two numbers as arguments. The first will be the real. The second will be the imaginary. Or you can parse one array, which contains two numbers and a real and imaginary. Or you can parse a string of the form bracket A plus BI, close bracket or bracket A minus BI close bracket where A is a positive or negative number and B is a positive number. Or you can actually give it a complex number and it will interpret a complex number. It will interpret that for you as well. By the way, I want to remind people in the US that when he says bracket, he means parentheses. If he means square bracket, he says square bracket. Yeah, that is one of those annoying cultural differences. And the thing is, the American way makes way more sense. Well, it might not be American. It might be that you're speaking programmer. I don't know for sure. No, no, no. Oh, okay. I'm speaking like way back to four-year-old sitting in school. Oh, okay. We never used the word parentheses. It was like trunk. It's one of those words, like a trunk twisters on an elephant, not a car. Ah. Oh, okay. Oh, so you mean if you were writing a parenthetical expression, you would call them brackets? Yeah. So you write right back to like baby school. Okay. They were brackets. All right, so I've done my good deed of the day in cultural differences. Fun to know. Yeah, it is. So yeah, so, and it actually comes from a word for a thing for holding up a bookshelf. So your one is like way more sensible. Yeah, because parentheses aren't gonna hold up a bookshelf at all. It's gonna flop right over. Exactly. Anyway, so let's, okay. So let's get back to our- Okay, so the last one I did interrupt you. The last one was, go back, was an object with a prototype complex number. So we can read a complex number from a complex number. Why not? Right, we've gone to all the trouble to define complex numbers. We may as well understand them. Okay. Seems like we should do that. So it's going to be, we're going to be adding to our prototype. So we're gonna start with complex- You've already got stuff typed on screen. What is it? This is everything from the last time. So this is everything we have. So let's remind ourselves. That's not a bad idea. Good. So function complex number, this is our constructor method, our constructor function, which creates just two little data points here. This dot underscore real is always starting at zero. And this dot underscore imaginary always starts at zero because we're very boring. Then we have our accessor function called real. So complex number dot prototype dot real equals function. We just sort of like getting real in and out. So we say, if you didn't give me any arguments, just return the value on the inside of the object. Otherwise, we take the value and we store it. Okay. And then we have the same thing for imaginary, very same code, just change the name. And then we have our big long two string that we did last time, just building up our pretty little human friendly string and that's where it stops. Okay. So we know that we have to go complex number. Yeah, so what are we doing again now? I know we're gonna create something called parse, but its job is to suck the numbers in. Yes. So to parsing means understanding. So we're gonna do our damnedest to understand whatever arguments are thrown at this function. So this functions job is to be as forgiving and as generous as it can. So I sort of thought the first words you'd write would be var parse equals function and then start putting some glop in there. But you started with the word complex number. Right, because we're adding it to the prototype. So we're basically doing what we've done here and everywhere else. So I'm going to be very lazy. Oh, did you say we're gonna add it to the prototype? I, well, whether I did or not, the actual text did. So let me, yeah. So add a function named parse to the complex number prototype. Okay, all right. So complex number.prototype.parse, okay, now. Equals, remember we're gonna keep reading more. Okay, equals function, yeah. So we're creating, we're making an anonymous function and we're setting, we're making complex number of product of parse become equal to this function we're creating here. Okay. Or become equals to, which we have Jill to thank for that nice wording as well. Jill's getting mention of lobster. Okay, so the first thing we say is that if there are two arguments as numbers, so let's start by saying, so how do we know how many arguments we have? You can use that dot length thing on. Well, it's not an array though because your ray is the second one, right? Well, yes, but arguments, the arguments are stored in this magic variable called arguments. So we can say, if argument dot length double equals two, triple equals two even, it can be as specific as we like there. So that means that there were definitely two arguments. There could be anything though. Okay. So now we need to make sure that we have a mental prokipise. So let us, okay, so if, let me think about this. Do you have to do all this if not a number? If not, not a number kind of stuff? Yeah. So if, let me think the nicest way. Do I say what we should do if it's an error? Function should learn a number of different ways. The following should all work. I don't actually say what I should do if I get told something I just can't do. So I'm gonna throw an exception. So I'm gonna say, okay, let's start by storing up. So I'm gonna say var new real equals arguments zero because we're computer scientists and we can't from zero. Okay. I'm gonna say var new imaginary equals arguments one. Okay, now we gotta make sure these things make sense. So the main reason you just create variables there is so that you can start looking at them and deal with them and have it make sense visually. Yeah, I mean, I could have called it arguments, square bracket zero and argument square bracket one throughout this, but that'd be annoying. Precisely. And so you could make the argument that there's like a millisecond of space and like a byte or two of RAM been quote, unquote wasted. But as far as I'm concerned, making the programmers life easier is not a waste as a sensible use of resources. Right. Cause you can make it super efficient and have it cause a buffer overflow or something because you made a mistake cause you didn't understand what you were doing. Right. Exactly. So if, ah, okay. I'm gonna reverse the logic here. So I'm gonna say if is not a number new real or is not a number new imaginary. Yep. And then what you can do is if either of those is true, you're gonna say throw new error. Look at me go. And he's typing in invalid arguments. Invalid arguments that I'm not feeling and I'm not in a very verbose mood today. I could be more verbose. It's cause he's having to type in front of video but I'm gonna keep reading. Good, good. Okay. So now we know it's not porcupine. It's not porcupine. So we can safely save it. So we can say this dot underscore real equals new real. It comes real. Okay. Yeah, it's exactly. So this dot on the, ooh. I'll read this dot underscore imaginary. This dot underscore thing is the more self-conscious you become about typing the worst you get at typing. And also you're being forced to read and type at the same time. And yeah, and talk and everything. Yeah, it's not normal. Okay. So all good here. So we tested those and now we've shoved them into this dot underscore real and this dot underscore imaginary. I think I'm following so far, Bart. So I'm gonna give a little comment here for my own sanity. Deal with. Porcupine. Two numbers. So that's the first of our thing. So else. Okay, now. All the other else's deal with a single argument. So if we look at. Well, hang on, hang on. What's our if it? Well, ah, ah, back, hang on. If the arguments dot lengths is equal to two, then we assign our variables and then we turn around shove them into this. Okay, so now we're back to another error. Oh, no, we're doing more embedded ifs. That's right. We are. So our options are two numbers, an array, a string and objects. These three here all have one argument. We don't know what the argument will be, but it will be exactly one of them. So the second one is gonna be an array of two numbers. Let me ask a question. Couldn't you have done this if, don't type, stop typing. Couldn't we have done our if isNan on the argument zero and arguments one after we define the if statement for the array? Cause that, otherwise we're gonna have to repeat this test again. That is a valid way to do it. That is a valid way to do it. I'm okay, I just wanna do it twice. I just wanted to see if I was following. Yeah, no, no, that is. So if the arguments is linked to or arguments zero is an array and the way we test is something is an array is we go if argument zero. Nah, that'll be much too easy, Allison. Okay, instance of array. Okay, so he's edited the first sign that did say if arguments.length is identically equal to two or arguments zero that's in square brackets, instance of array. So that's a test to see if it is an instance of an array. Huh. Okay, now we need to be a little more clever here. So either. He's adding to his comment. That's two numbers or an array of two numbers. Why does arguments square brackets, why does it have a zero there? On line 118? Yeah. Cause I am testing if the first argument is an array. So it's either two arguments, number, number or one argument that is an array of two numbers. Okay. Okay, gotcha. So if I gotta do a lot more jigglypokery here now. Yeah. I do. Uh-oh, what are you changing? No, I mean, I'm just thinking out loud for a sec. I know I'm gonna need that. So if we got them as two separate ones, then we do what we had before. So if we got them as two separate ones, we can copy paste you a lot up here. This is making very good audio. Yeah, look, this is video for a reason, right? Yeah. Okay. You're my commentator. I'm typing. Okay, but I don't know what you're doing. I don't know why you're really concerned. Okay, so I am now rearranging my code purely to position myself to actually do something new. So if the arguments are at length two, we just do what we did before, which is we take them directly out. Otherwise, we can't take them directly out. Now, I can't declare my variables in here, so I need to do more repositioning of code. Cause I'm changing my, we're changing our mind halfway through here. So that means we have a little bit of work to do. I'll finish repositioning my code. My indentation seems to got all messed up. Yeah, close enough. You probably got a space in there, so there you go. So he's typing a lot of stuff and I don't know why. I'll explain it now in a moment. Okay, so now our code does what it did before. So we say, we're just creating two new variables, new real and new imaginary and we're giving them a dummy value for now. And we're saying, if we got two separate values, new real is the first of the two separate values and new imaginary is the second of the two separate values. Otherwise, it must be an array, right? So we've said if it's length two or if the first one's an array, so the else here is for what to do in an array. So how do we get new real from an array? So I'm confused because we're treating the previous one like it's an array. We're saying position zero and position one and that's array wording. It is, but our arguments are an array but in this case, the first element of the array is gonna be an array. So arguments zero is an array. So argument zero would be a whole array. So argument zero, zero will get us to the first element in the first element of the arguments array. Yeah, no idea why you're saying that an array has an array inside it. Okay, so the arguments are always an array. So if you give no argument- Oh wait a minute, because there's two values for each one, so it has to be an array and an array. It's two dimensional. Yes, in this case, it's, well, it is two dimensional but possibly not for the reason you think. So the first dimension is just the arguments array and then the second dimension is the array that is the first argument. So arguments zero, if it makes more sense I can do it like this. I can say var the array equals arguments zero because whenever we're saying we pass an array as the first argument, so we just pull it out. Then we can say new real equals the array zero and the array one. Does that make more sense? Nope, because you haven't explained to me what I said I thought I knew you said no you don't and then you started typing again. So what I said, what I thought I understood briefly till you said I didn't was that it's two dimensional because each element in the array has two values. Each element in the array has two values. It's got a real and an imaginary. But there's only one real and an imaginary. So it's arguments is an array. So arguments is an array which has a length of one. Where did the, okay, arguments is a word you made up or that's a sacred word? Sacred word, special word. Inside any function arguments gives you access to all the arguments that were passed when the function is called. So when you say my number dot parse you're gonna give it some arguments for it to try to understand and they're gonna be accessible as arguments zero, one, two, three. And arguments is always an array. Arguments is always an array, yes. Okay, but we're gonna pass another array to it. Yes, so if we call our parse function with an array as the one and only argument, well then arguments zero is an array which contains then two things. So argument zero is always the first argument even if that argument is an array. So you may have an array that contains an array which is exactly what we have here. So which is why we have this. Let's keep going. I'm hoping maybe you have an example that will explain that. That it'll be. Well we are because we're going to, I'm gonna write this, I'm gonna re-simplify this if that's okay. We're going to test, we're gonna have to test our function. We can't just assume it works. Right, that's what I was saying. Maybe your examples that you test it with I'll be able to understand what you're saying. I hope so. Usually seeing code work is more illuminating than seeing code sit. Okay, so now what we've written, if arguments on length is identically equal to two, we've got new real is out of, that's becomes argument. Okay, you're still typing. Yeah, I'm just putting in comments. I know, but if you're typing I can't read. Oh, okay. Hold up for everybody. If arguments.length is identically equal to two, then new real is a variable we've already defined up above. We say new real is equal to arguments. Yeah, you might want to turn off notifications. Can I say if we slide over and we go, where's that magic do not stir button? Click back on notifications. Yeah, there we go. Do not stir, good day. All right, one more time. So if arguments.length is identically equal to two, we've already got new real and new imaginary variables we've defined. So new real becomes arguments, position zero, new imaginary is arguments, position one. Okay, I'm there. Else, and this would be the case since our only other condition is we've got an array. Yes. Then new real becomes arguments, square bracket, zero square bracket, square bracket, zero square bracket. And the second one, new imaginary is square bracket, zero square bracket one. Okay. So if I highlight this bit here, square arguments, zero will point to the array because we're saying if it is an array. Okay. And then another set of square brackets is go into that and give me the zeroth element. Have we seen that writing before like that? We probably have. Okay, it looks vaguely familiar, but I wouldn't have thought of it. Okay, I'm with you now. Okay, good. So that's all saying, and then we're saying if it's valid, we're already talking about the not goofiness. Save it or save the new values. Okay, so we now have two out of four taken care of, I think. If we go back here, so we're saying two numbers as arguments and an array of two numbers as a single argument. Okay, those two are done, tick. A string of the form, ble, ble, ble, ble, ble, we're positive or negative, blah, blah, blah, blah. Okay, now things get more difficult. Okay, so. Else. Oh. I thought you would start typing before the save the new values. I thought that would be the last step of every one of these. Well, it all depends on how you architect your code. You could architect, let me think about this. You could architect it that way, I suppose. Yeah, actually, you can do that. Okay, well then we don't wanna say if arguments length equals to or. Oh, well, don't change that again. That'll be really confusing if we have to change it. That will be really confusing, yeah. I was thinking of a sort of as two numbers would deal with that case and then we'll deal with the string and then we'll deal with the other stuff. Okay. So we'll say if, else, if argument's, that's about right, yeah, okay, change color, good. Are we gonna ask if it's the type is a string? Yes. So if type of, look at me. Type of arguments zero is exactly equal to string. And single quotes, okay. I'm gonna put this, we'll come back to that. I'm gonna build out the full structure here. Okay. So we can see the full structure. So now he's jumped down and he started the else condition, okay. So our other possibility then, what's our fourth possibility? Ah, yes, our fourth possibility is that we have another complex number as an input. So else if arguments zero instance of complex number and then the final possibility is that it's just absolute garbage that we can't understand. Hmm, I thought we already dealt with the garbage. Well, no, we dealt with some of the garbage, right? We said that if there were exactly two arguments and they weren't- We got that whole isNan stuff. Right, but that's only happening if we go into this if, right? It's only happening for those two cases. So this is the generic, maybe you gave me no arguments. Maybe you gave me a thousand arguments. Maybe you gave me an argument that's, I don't know, some sort of weird thing. Okay, I do like watching you do this because I'm watching you think out the structure and then put in what do you do about it? Yeah, and see when we did the first one two weeks ago, all this was semi-recent in my head. I've completely forgotten how my sample solutions work now. So I really am reinventing the wheel here. Good. So a new error in valid arguments. Again, not being particularly verbose today. That's fine. Okay, so now this is the fourth one we're doing. Wait, oh, we're gonna, okay. Do we do the third one first? The string one first? I was gonna do the easy one and get that out of the way and then go back to the hard one. The easy one's the last one? Okay, all right. The easy one is the instance of complex number. Yeah, because if it is a complex number, we already know, oh, we know exactly what it's gonna look like. We know exactly what it is. We don't have to worry about sanitizing it. It's all been pre-sanitized for us because we have our accessor method. So we can just say this dot underscore real equals. That's a minus. Yes, it is. Becomes equal to arguments zero dot real using our accessor method. And we can say this dot underscore imaginary becomes equal to arguments zero dot imaginary, assuming I can spell. Okay. So that's calling the, why are there parentheses after real and imaginary? You're not calling a function there, are you? We are most certainly calling a function. Oh, go to the top again. We have something. We have to find these functions. So we're saying that they exist here. They exist here imaginary. So these are our accessor methods for reading in and out. So we wanna read out. Got it, got it. Yeah, so we're calling our accessor without any arguments. We're saying, yeah, read it out. Argument zero is a complex number. So read out the real bit. Argument zero is, yeah, so read out the imaginary bit. And then store them. So it becomes equal to, so that's easy, right? And this is where the hard work begins. Okay, and what he's pointing to now is the string piece. Right, so we gotta deal with the string. Now, there are lots of different ways we could slice this, but I am going to use my best friend, the word regular expression. Oh, dear. Okay. Yeah, I know, this is why I decided that we would get the easy stuff done. So our whole function is ready. You're in part from this bit. Okay, so deal with the string. And the string is just someone's typed in the text. Three plus five I. Yes, now I have said, actually, I want the parentheses there. So a string of the form print A plus BI or A minus BI. So I have been a bit strict here. All right. If I was speaking evil, evil, I would be, I would accept like 20 different possible patterns, but I'm only expecting. I think you've been just evil enough here. Yeah, I thought I'd be nice to people. So. This is your version of nice. I think it's torture, but okay, keep going. Okay, so if something happens, we'll figure that out in a minute. So how do we do a regular expression? Well, we have a match function. Let's go check our... So you're flipping over to your... I'm going to read my own notes, JS Miscellany. I can't believe I've got bookmarks of this stuff and you don't. Mathematical, regular expressions. Thank you. So. It is regular expression lessons. Perfect. That's what I want. I want my matching. So that means we're going to use the exec function. Okay, perfect. Sorry, I said to refresh myself. Okay. And you're at the Miscellany one. Yes, I am. So create a regular expression to match imaginary numbers. So far, IMG or E. That's as good a name as any equals pattern. Okay, starts with an ends with. That's easy. Well, we know what it has. Okay, so in regular expressions, I always do this. Can you move your cursor? It's on top of your... There you go, thank you. Okay, so I always start my regular expressions by just putting starts with ends with. I know I'm going to want that. So starts with was slash carrot. Nends with was dollar slash. Okay, no, so the two slashes are the start and end of the whole regular expression. Okay. And then the carrot symbol or whatever you want to call it is start of the string you're matching and dollar is the end of the string. So we don't want any... We're not going to accept, except say boogers, parens, and then a valid number. We actually want the parens to be the very, very first thing. So we're not going to be too forgiving here. Okay. So we need a parens. And so the easiest way to match a parens is just to match a parens inside square brackets. Now we could do that. We could either do backslash parens, which I don't like, or we can do the character class parens. Which you're putting inside square brackets. So a square bracket means a character class. So any one of the following characters is acceptable. So there are opening quotes. This is where you're crazy that this makes sense. So he's just written square bracket, left paren, right square bracket, left square bracket, right parens, right square bracket. Which you should read as match exactly a bracket. So, okay, our parens, our parens to see. Not confuse ourselves completely here. Okay. So then we need to have one or more digits. So slash D is digit. One or more is plus. So that's one or more digits. Now there might be a minus sign here, right there. Perfectly valid to have a minus sign in front of various of minus four I. So we could have the symbol minus, which may or may not exist. Do you remember zero or one occurrences of? I remember you saying those words and typing a bunch of stuff on the screen with brackets and such. Okay. Question mark means it may or may not be there. So we may or may not have a minus sign. Then we have one, zero, sorry, one or more digits. Then we need a space. That's a space. Then we need either a plus or a minus. Now we need a space. No, we don't. Do we? Do we need a space according to what I said? I mean, look at my own. Yeah, okay, we do need a space. Plus or minus, followed by a space, followed by one or more digits. So believe it or not, that's the regular expression we need. So you don't need to go through it all again, but what would you, what would the basic idea of how you would do that without using regular expressions? Well, the other way I guess you could do it would be to start splitting the string. So you might say, is the first character or parentheses, is the last character or parentheses? Okay, cut those two off. So like my slice function that I learned from Codecademy. Yeah, so you could slice the first bit off and make sure it's a prince and then throw that away and then slice the end off, make sure it's a prince and throw that away. And then you'd want to slice off the first few bits until you meet a space, I guess, and then see if that's a number and save that. And then you'd see if you've got a plus or a minus and then save that. And then see if the next bit was a number and save that. It would be, you could do it. You know, you just slice by slice, nibble it and as soon as you meet something that's garbage, stop because it doesn't matter why it's wrong. If it's wrong, it's wrong. You know, call it a day, we're done. All right. So I do prefer regular expressions though. And the key point is you build them up like I just talked through it. So you start with the two ends and you just start building up what you want. Now, we need to gather up pieces of this. So we want to group pieces using parentheses. So the first piece I want is the first number. So I'm going to put that inside parentheses. Then I want to know the same parentheses you were talking about a minute ago because they're not inside square brackets. Correct. And that the reason I have to put the parentheses in square brackets is so they don't get confused with the real, see parentheses has a meaning within a regular expression, which is a group. So I want, I'm going, I want three things I want to know. I want to know a number, a symbol and a number. So I have made three groups by putting parentheses around the three bits I care about. And they're going to come out as the first match, second match and third match. I am G or E, dot. I have made a commitment to learn as, work as hard as I can to learn everything you've taught me but I'm not learning this. That is fine. That is, I'd say that was optional. So maybe I'll set the video to fast forward to this part. Well, somebody else might care. Okay. So the results, no, there are people who may love regular expressions as much as me. Okay. So we're going to take our regular expression and we're going to execute it against arguments zero, which is our string. And then, so the way this works is that the result is either going to be equal to null if there was no match or there is going to be a match. So if the result is not equal to null, then we know it was all good. Let me, ooh, wrong one. You'll do that at least once. You just lost your five dollars. Five dollars? I bet you five bucks, you couldn't do it reliably the whole show. You don't remember the whole show. Okay. So not, okay, I can be more strict. I can be not triple, exactly not equal to. Okay. So if that's all good, then we can say this dot underscore real equals result one for our first match. This dot underscore imaginary equals results three. And we need to be a little careful here because if it was a negative number, we need to make imaginary be negative. So we need to say if result two is equal to the minus symbol, then we say that this dot imaginary becomes equal to zero minus, sorry, becomes equal to zero minus itself, right? So if it was three, then it becomes equal to zero minus three, which is minus three. Does that make sense? Yep. Yeah. Strangely enough, I find the maths harder than anything else. My maths is right, right? We'll find out. We'll find out. So there we have our string matched. Okay. That was evil, but not long. That's actually, that's all for the cake. I just went over ready email for a little while. I'm just telling you. Okay. So we can have that. Okay. Let me just double check. But I think we have done our four things. Two numbers as arguments, we did that. An array of two numbers, we did that. A string, we did that. And an object, we did that. Okay. So let us test our parse function with this code. So, whew. Nope. Nope. Wrong button. You know, there's one you don't have to do that. Hover over it again. Yeah, I know. The far one, no, no. Keep going. Keep going. That one. Nope, back one. Hit that one. Nope, back one. That one. The one that says copy just hit it and it highlights it too. And so you just hit command C. Okay. We'll have it now. So this is, now we see how many typos I made. So then what does this code say that we told it to do? Okay. So we are now going to test the parse function. We have hopefully correctly written. So the first thing is we say, construct a new complex number and print it out. So that we should just print zero because our complex numbers always started zero for now. Test the two number forms. So then we're going to say CN dot parse two comma four and then print it out. Okay. Then we're going to test the array form. So we pass at the array minus three, 5.5. And then we print it out and hopefully that'll have worked. And we're doing, by the way, we're using PBS let's say CN three dot two string where we built two string in our. Yes. So we're going to always use two string to turn it into a string. Yeah. So then we do the difficult one and we test all these different strings two plus six I two minus six I minus 2.76 plus 6.2. I, and hopefully they'll all two string. Oh, I already see some problems with my code, but I'm going to continue as if there aren't. Cause this is good. And then test the complex number object. So we're just going to pass it in a new complex number into the parse function. You didn't try passing it garbage. We can do that, I feel like CN three dot parse. Actually, we'll do that in a minute cause that's going to, and then that'll just stop our code. So let's see how much of this is working and how broken this is. Nope. Instance of, yeah. That's because I can't spell. See in my brain, in my brain, instance of should be capitalized. However, in reality it isn't. Oh. Instance of, instance. Put the O in. I'm hitting the O key and there's nothing happening. Is my O key broken? That's interesting. Is my O key broken? Or is the playground just having a different button? No, okay. It seems like I cannot type in here anymore. Try copying it all first before you do anything else. That's interesting. Maybe you just hit the length of it. That's weird. No, cause you had, you had a zero capital O. Okay. Instance of, yeah. Okay. Instance of definitely doesn't exist. Not for me to try. So now we're looking for instance. Okay. Let's see. It's not working, huh? This time trying not to run it first. Yeah, exactly. So instance. Okay. What? Okay. Is it just, what is, the universe is not making sense? Oh, there it goes. Instance of. Instance of. Yeah. How did you break it? It's not working. It seems that I hadn't fully de-selected the search. It seemed to be still stuck in the search. That was very strange. Okay. Let's see what other. Oh, interesting. Let's see what other typos I have, because I'm sure there's more. No, there's another one of those. Okay. Maybe we'll do a find all. Instance of. Oh yeah, three times. Instance of. Instance of. Is that capital O? Yes, you did it right once and wrong twice. That is really weird that it's. That's a bug. So for people who are listening, he's typing an O, but it's typing it up in the, in the search bar. Yeah, you're good now. Okay. Now we have a different. Oh, okay. Well, we have, we're having issues here. This is not working exactly as it should, but we have some stuff. It looks like it's working. Oh, it's doing something. I'm not sure it's doing the right thing. So let's see why it's not doing this. Okay, so. Your first one is just. First of. Empty. Fine. Okay, so no problems as far as here. All good. The two number form, two comma four. Two, four I. Right. All good. The array for minus three, 5.5 I. Looks perfect. Fine. And our string one is broke to de-broke. So the string was. Oh, it's just repeating what it had before. Oh, interesting. So that's cause it never became. Yeah, because we didn't put an else here. Ah. See here. Throw new error or could not parse a string. Hmm. Oh yeah, it's been day to day. Yeah, excuse for an error. Now we know what day Bart takes the trash out. Yeah, and every second, one week it's recycling, the next week it's real stuff. And it's interesting too that it disobeyed your, you turned on do not disturb. Yeah, I did. That's interesting that. Okay. It's still not working. Still not working, but it's not. So it's not jumping to the next one. It's looking like I was expecting, yeah. It's remembering the previous this dot underscore real because it hasn't become the new one. Yeah. So which one is it getting stuck on? Was it the string one that you put in? Oh, I'm just a silly booger. I sometimes do silly things. When you attack the else onto the wrong if, it doesn't do what you think. Oh, okay. Because it means something completely different. Now, okay, now I'm expecting sanity to return in the form of a giant big error. Because. There we go, giant big error. Okay, sanity has returned. And so you knew it was going to screw up because you noticed an error in your code of the test? I was pretty sure this is what was happening. I was pretty sure the reason it wasn't changing was because the regular expression wasn't catching. So we've made a mistake in our regular expression. Oh, let me debug that for you, Bart. Okay, so the slash at the beginning of the end means something and you got the caret and the dollar means the beginning and the end. Yeah, okay. The slash is that we had a regular expression and I lost you after that. Okay. Actually, let me see if I can see it. So we expect to see a parentheses and then the next set of parentheses is that's our first part of the expression. Yeah, we're expecting maybe a minus slash D plus. Now we're expecting a space. Now we're expecting. What was if there a question mark with that one was what I was gonna ask with the plus minus? Well, because it's one or the other. Oh, it has to be one or the other. And the first minus with the question mark means it shouldn't be, but it might have that. Why wouldn't you do it the same way? Why wouldn't you? Zero or what? Oh, because it might be nothing. Yeah, it could be nothing. Exactly, like four is fine. Minus four is also fine. Okay, but on the next one it's gotta be a plus or a minus. Okay, and then we get another parentheses then we get a space. Our last piece is the slash D plus which means one or more digits. So that look at the C awfully correct to me and it's not matching. So what else could be wrong? Could it be the input? Let's let's go down and look at see if you've got spaces or something in it. The two parentheses, two plus six I. Do the quotes, are the quotes supposed to be there? Alison, Alison, Alison, Alison. What? We've forgotten the I. Should the I be inside that little parentheses? It should be there. We don't want to capture it. We want to capture what goes before the I but the I still is part of the pattern so the I needs to be here. Okay. Do you like that I actually was able to read it? Yes, yes I do. Okay, now we're still gonna run into trouble but we'll have one more good line before we have trouble. Okay. Two more good lines before we have trouble then we get a problem. Two of the six plus I's. Here's where we hit our problems now. Okay, so it's not sure what to do with a decimal. Yeah, because our pattern has no mention of them. No mention of them whatsoever. So we could have here a period followed by. A question mark? Yeah, it will be in a moment. It'll be a period followed by one or more digits and then all of it gets question marked. Okay. Because otherwise you could have a period just hanging there, which would be a bit weird. Copy and paste that piece, would you? Just in case it's wrong, we do it wrong twice the same way. Wait, you didn't get the parenthesis. Yeah, we consistently wrong. You missed a parenthesis on the far right. I didn't. Oh, no, no, no, gotcha. Are you right? It's not easy to tell that I didn't, but I didn't. Now we have, okay, so that pattern will match but now our numbers are out. So let's count the opening brackets. You're still one. You're now two. You're now three. So what was two becomes three. What was three almost certainly becomes four. Yes, it does. Because we've added more parenthesis, our numbering has changed. Okay, that's the part when I was doing my email right there. Okay, ready? So in theory, we should have no more errors and this should now work and pass our test. Way, I think. Not way. Should the last one be three, four? I know it shouldn't. Unless you rounded it. Oh, no, it should be three, four. Sorry, line 186. Oh, line, line, line. Okay. Okay, good. Yay. Our code pass to their tests. And this is how it really works, folks, right? When you're really programming, you make mistakes and you write test cases. Don't assume your function works, test it. Yeah, the one thing that bothers me with testing and Steve and I were talking about this recently, the company I used to work for would work on some new project and they would want people to test the code and they would give us a list of things to test. They would say, click here, click here, click here, write down what you get. And I'd always tell them, I say, I'm not gonna do that. Cause if you wrote those instructions, you already did that. I'm gonna go in and just flail around in the program and see what I can get to break. And everybody else would doodlifully go, oh yeah, it all worked perfectly. I'd come back with this plethora of weird cases that caused problems that they didn't think of. Yeah, at this level of testing, we're not really testing the UI, we're actually testing the function. So at this case, what you need to test. But I find things that broke. I don't mean UI. I mean, I could crash it, do all kinds of things. What you want when you're testing functions is you want a list of inputs and outputs. So, you know, like we have here, can we deal with minus numbers? Can we deal with decimal points and stuff? Oh, sure. But this would be like the test that they would write and then Allison would go and run the same program and type in boogers which you haven't tested for. True. Okay. Okay, that's all right though. So we actually finished. We have, well, we've done seven, test your parse function with the following code, good. Okay, eight. Now let's make our constructor more smart. So we've now written this parse function and it has all of these brains it knows how to deal with all the different things. So wouldn't it be nice if we could update our constructor so that it gained all of that intelligence that we've just written? So instead of having to say var, so instead of having to say var, let me see, where's our sample code here? Var CN equals new complex number and then say CN dot parse two comma four. Why don't we just say new complex number two comma four? Wouldn't that be easier? Yeah, but it doesn't know for parse. Right, well, yeah. Right, we haven't written that into the constructor. So we're now gonna update our constructor to give it that intelligence. We've put in the work here by writing parse. So now we can use parse. And this is the point where your brain may mildly explode because we're going to scroll up. Sometimes I think you punish me for understanding too much. You go find something else to hurt me. Arguments, I'm going to update my comment here. Same as parse. So we're gonna, okay. So he's at the very top of the code now and he just changed his comment to say that the arguments can be same as parse. Yeah, I'm gonna say if, no. So default to zero, zero. Right, just, that seems like the same thing. But now we're gonna say, deal with arguments. So if arguments dot length double equals one, I'm going to say this dot. Can I stop you, Bert? You can. Are we gonna not need all that code we wrote? Oh, well, what code? All the stuff that we wrote today, which was dealing with arguments. Down below, you're saying you're gonna- Oh yeah, we're not deleting it. No, no, we're leveraging it. We're calling our parse. Oh, right, right, right, right. Because this stuff isn't linear. It's linear. Yes, because we're- Stop typing, don't know you're cheating, typing while I'm asking questions. So we can go back up to this function at the very beginning called complex number and we can now use that stuff we wrote at the end of the code because that stuff down at the end calls this after you give it all that information even though this was written first on the piece of paper. Right, because nothing really happens until we say new complex number anyway. Yeah, that's gonna take me a while to get used to but I get it, I get it, I caught up. Okay, now you just type- Yeah, that's the bit that may explode your head. So that's, we got that out of the way. Good, so now we're gonna say- Okay, but you just typed a bunch of stuff and I don't know what it means yet. Okay, so if we got one argument into our constructor, just pass it on, just say this.parse with the same argument, just hand it on. Argument zero is the first argument. Else if we got two arguments, pass those on to. Arguments.Language, spelt right, isn't it, th? Yeah, double equals two. We'll exactly equals it. I'm trying to get into the habit of exactly equal thing because it's better. We can say this.parse argument zero arguments one. So what we're doing is we're saying if the constructor was given arguments, just call the parse function with those same arguments, either one of them or two of them. I don't know what this is doing. I don't know why we're doing it. Ah, because I, okay, so this is what we used to have to do. So we used to say var my CN equals new complex number. And then we had to say my CN dot real three. Then we had to say my CN four. And then we can do a PBS dot say my CN dot two string. Right, well, that works, three, four I. I can replace those three lines with one line. Show me what that line is going to look like. If. So what we're saying is when we're building our object at the point we're constructing it, we may as well say what we'd like. Rather than constructing it and then giving it a value, why don't we give it an initial value that's actually what we want? And the only way to do that is to give arguments to the constructor. And the only way that that can work is if the constructor has the brains to do something with those arguments. And we've already written the parse function which has all that brains in it. So let's just use it. Let's hand the work off. It seems like you could have called function complex number and it's no go back up to the top. It sure feels to me like you should have been able to say function complex number and instead of leaving putting no arguments between the parentheses, you could have put real comma imaginary. Okay, but then it would only work that way because we're calling parse, it will also work like this. I can also say three. The three plus four I. Four I. Because we've built all this other logic that says we can put in strings and all kinds of others. Okay. So basically we put a lot of work into that parse function. Okay. So let's leverage it, let's use it. And that's a very, very common model. So you write the brains to interpret input once, call it parse, because that's just what people call these things and then use it any time you need that functionality, including in the constructor. So don't write it twice. Don't write a constructor that then parses everything and then a parse function that parses everything. Write it once, use it twice. We don't eliminate any code. We added a little more code to say just make it easier to input into the function. Yeah. Just make it easier to set the initial value. So that is. Can I read the top again? Can you read the top? Absolutely. Now I want to read it, what it says. It says, if arguments.length identically equal to one, this top parse argument's zero. And that's. So argument zero is the first argument because we count from zero because we're special. But we have, there's always two arguments. The real and the imaginary number. No, there's one argument here, right? This is an argument that is a string. So this, in this case, it's arguments.length is one. So in we go, we pass that string through. Okay. And if we did two of something, then do the other one. Exactly. Exactly. Then we pass the two through. Oh, okay. It says to say, well, all we're just doing is we're just plumbing. It's like, we're just connecting it together. We're saying, if you gave me two things, I'm going to give two things to parse. If you gave me one thing, I'm going to give one thing to parse. Okay. And now if we, oh, so we've just basically, we've gotten a lot of value there for very little typing. Yeah. So update your constructor so it can accept the same arguments as the parse function. Do not copy and paste the code. Instead, update the constructor to check if there is one or two arguments. And if there are, call the parse function with the appropriate arguments. That's what we did. Test our constructor. Okay, well let's give it a good old fashioned test then. Is it that one? No, it's that one. That one, yeah. So you hit that one. You still have to command C. Yeah, it even tells you, isn't it? Cute. I know. I have more experience with this than you do. I usually write it. I don't usually run it. Yeah. Right. Okay, so let's have a look at our test. Test the two number format. So we're saying new complex number one comma two and then two stringing it. One, two, okay. Test the one array format. So square, two comma three. That worked. Test the one string two minus six I, two minus six I, and test with a complex number. New. Okay. It all worked. All worked. Test passed. I like when tests pass. Okay. So now we can easily two string our numbers. We can easily set the value. So we now have the ability to make any complex number we want, but it has no brains yet. How do I add two complex numbers together? Wow. You don't. You become a mechanical engineer instead because you don't believe in them. That is an easy way out. Let us try to not do that. Let's try to actually make this. So let's get rid of our test code. So complex, complex number dot prototype with one Y dot add. But you shut the T. Prototype. Okay. Actually, this is what we all need is someone to watch us type to go, no, it's a lower case O. It's called the buddy system. Maths is supposed to be math library, right? Yeah. That's actually called the buddy system of programming and it's done in places where it's important. Yeah. Huh. You have a coding buddy. He sits with you and works for you. So you're spotting each other's mistakes. Can't play like a pilot and a copilot, I guess. Yeah. One of them can fly the plane, but the other ones there to make sure they don't crash into a hill. Okay. So. Read this out loud. Add a function named add to the complex number prototype accepts one argument, a complex number object and adds it to the object the function is called on. Why do you always talk in circles? That's a circle. Well, we are in a circle, right? Because you have a complex number and you want to add a complex number to it. So there's two complex numbers in the equation. All right. Why don't you just say and add them together? Well, no, because you're gonna have, so you're gonna start off with complex number one which has a value and then you're gonna say add complex number two to me. So when you're finished, number one is gonna contain the result of the addition. So the first complex number is an object and then you're gonna add another one to it. Okay. Yeah. So the way you do that is you add the two real parts together and the imaginary parts. Correct. Okay. Well, that was, okay. So I'm gonna call it CN. I'm gonna call my argument CN for complex number because I don't want to type out a long name. Is that okay? It is wonderful. Okay. So we're going to say if CN instance of complex number. So in other words, if we were past the complex number, then we can do our adding. Otherwise we got to get cranky. Otherwise we say throw new error type error. I'm being very unimaginative with my errors today. So we add the two real parts. So we say this dot underscore real becomes equal to CN dot real. No. Well, almost. Becomes. There. Are you going to allow me to plus equals? Yeah. I'm all over plus equals now, but I'm not sure why cause it doesn't, it isn't anything yet. Why you wouldn't just unequals to start with cause it's plus equals later, right? Well, no. So this is the add function. So we're adding at this stage in the game, the object exists. So it has a value. So we are plus equal thing, right? We're saying that whatever's inside of us becomes whatever it was plus the real part. What's inside it right now? That entirely depends at what point you call add, right? Remember nothing happens until we say go. We're just saying if someone says to add, this is what you do. And then you say whatever is in me now, make it bigger. But there's nothing in it. There's nothing in you. Cause all you've got is what you just started with which is CN and we've already got, you're saying add plus CN. But we're adding this function to the two. We're saying that every complex number will have the ability to have something added to it. Oh, that's what you meant. So an existing complex number. Yes, yes, yes. Oh, you never said that. Okay. That's what I tried to say. I need to find the theology that works. All right. So the imaginary number becomes equal to itself plus CN dot imaginary. Cool. Okay. That is that. I think let's test that. It seems too easy. So where's the first one coming from? Okay. So the first one isn't the... So we need to make an imaginary number with our constructor. So we say var my CN equals new complex number. Give me two numbers, Alison. Six comma negative seven. Six minus seven. Okay. And then we're going to say... Okay, I'm gonna be very boring. Let's say N1 CN1. So CN2 is a new complex number. Two more numbers. Negative four comma negative three. Okay. So we're adding minus numbers. You're making life difficult for yourself here. Okay. Yeah, but I know it should be. It should be two minus CNI. Yes. Yes, it should. Okay. So var CN1, we gave it some values. Var CN2, we gave it some values. So now we can say CN1 should have CN2 added to it. So CN1.add CN2. Oh, hang on. Hang on. Let that rest for a second. So he typed CN1 plus add parentheses CN2. Dot, dot, period. What? CN1.add. Dot add, sorry. CN1.add, so we use the add function that's in our prototype to say start with CN1 and go throw a CN2 on top of it. Yeah, I never would have thought to do that in about eight million years. Okay. This is why we have these examples, right? Because whether we're doing complex numbers or something else, the concepts remain the same. So we're saying all complex numbers have the ability to have another complex number added to them. So we're adding it to the prototype. So now we're gonna do a PBS, let's say on CN1.2 string and what did you say we should see? I said we should see two minus 10 I. Two minus 10 I. Two minus 10 I. Look at that. So our add function works, okay? I have a feeling we can copy and paste for the subtract function and just do some minor tweaks. Pretty sure that's what I said to do next. In a similar vein, add function called subtract. We can copy that one and paste it, right? Yeah, already copied and pasted. So we're calling it subtract and then we're saying minus equals and minus equals. And I'm just gonna sort of assume that that worked because we have test code coming up in a little bit. Now, multiply by, this is where things get evil. So I know we're gonna make one full. Did you just run it? I looked away for a second. I didn't bother, to be honest. I ran it, there's no errors, but I didn't do all typy typy. Oh, and you erased our previous typy typy. I did, which I wish I hadn't. Okay. Okay, now we do the hard part. We're gonna write a multiply by function. Oh, and that's hard because- Multiplying complex numbers. You have to remember how to multiply complex numbers. Yeah. So complex number dot prototype. Dot multiply. I've gotten very lost here in typing type prototype. Yeah. Multiply? Multiply by- Okay, can you remind us before you go too much further? What, how do you multiply two complex numbers? Ah, this is, okay. So if you, right, so to multiply by, there's a rule which is written down. You can either get it for first principles, which is evil and horrible, and I wouldn't urge anyone to do it, but it's basically if you have A plus BI multiplied by C plus DI, the answer is AC minus BD plus AB plus BCI. Basically, I'm just going to implement this rule blindly and assume that the mathematics is correct. That's kind of interesting. It's almost like, well, so it's sort of like multiplying two- I believe it's called a cross product. Yeah, cross products, yeah. Okay. So I'm just going to blindly follow this rule. So I'm going to need an A, a B, a C, and a D. So let's create, and actually, okay, very first thing I'm going to copy and paste our, let's check to see that they didn't give us garbage rule. Okay, so we're going to need an A, a B, a C, and a D. So var A equals something, we'll fill it in later. Var, yeah, interesting when you're off by one on your keyboard, if var becomes a bat. Var B equals something. Okay. Var C equals something. And var, var D equals something. So now let's go back and look at what our somethings have to be. So A is going to be the real part of our first number. So A is this dot real, what's B? B is the imaginary part, okay? So this dot imaginary, what's C? C is the real part of the second number, isn't it? Yeah. Yeah. So C is C and dot real. Okay, so A and B are of the existing complex number. Yes. That's why I called it multiply by, just to sort of say. I have one and I'm multiplying it by the other. And then C and dot imaginary, we are going to call D. Okay. Okay. And now we can say that this dot underscore real becomes equal to, when does it become equal to A? Copy that into a note, into a comment. And we don't have to keep going back and forth. That's a great idea. Actually, that's just a really good idea, just from a pure. If I was doing this for real, I most certainly would. Yeah, that's what I do with all the, when I'm trying to do it on my own is I copy and paste your instruction so I don't have to go back and forth. All right. There we go. If I was doing this for a work or something, I would either have a link to a webpage explaining how you multiply or I would have a comment like this. But I would certainly have some sort of explain what I'm trying to do. Yeah. So real becomes equal to A, multiplied by C, AC minus B star D. That's correct, isn't it? Uh-huh. And then this dot underscore imaginary becomes equal to A times D plus E times C. And then just because I know technically- I wouldn't have driven me crazy enough to put the parentheses in first. Technically speaking, you don't have to put the parentheses in because the laws of precedence, blah, blah, blah, blah. Yeah, but no, you better. None of us actually believe in those laws. It's also, it just makes the code easier to maintain. There's no doubt what I meant. Yeah. When I do it this way. None of us really do believe it. That is also true. Or else we can't remember and we're too lazy to go look up the documentation. So the last thing we have is something called a conjugate. And a conjugate of an imaginary number is very straightforward. We aren't gonna test that one? No, it's okay. We're gonna test them all here. I have test code here. We don't know what the right answers are anyway. That's a fair point. Actually, I'll start working on the arithmetic while you do that. A conjugate is a nice easy one. Two plus three i becomes two minus three i and two minus three i becomes two plus three i. Basically, you flip the sign is what you do to conjugate. Yeah. What is a conjugate for? It's the first step towards a division and then I saw the mathematics for an actual division and decided to stop the assignment there. Bless your little heart. But I did. So I figured conjugate is easy, right? It was just a bit of basic mathematics. So we can do that. So dot conjugate of. This function should, now this one is a little bit different to what we've done before. So we're, right, so let's just, we'll get back to the English in a second. I'm just gonna put my foundation in place function blah, de blah. Okay, let's go back to the English. A function named conjugate of to the complex number prototype, this function should return a new complex number object with the sign of the imaginary part flipped. So we're not altering ourselves, we're returning a new complex number. So that's slightly different to what we've done before. Okay. You're still there? Yeah. So we know, we're gonna say, we're gonna say var, var conj, that'll do, equals new complex number. Okay, great, that bit's easy. Now what? What should be in this new complex number? We know we're gonna return conjugate, but now we gotta actually figure out what to do. Well, the real part never changes, right? I'm confused by something. We've never returned anything else before. Why are we suddenly returning? Because I said here, the magic word, this function should return. Okay, and we never, you never told us to return in the other ones. I did not. None of the other English has returning bits in it. So we have not been returning. So that was just for fun. Yeah, this is, well, the reason this one is here is because it's different, right? That's different English and results in different code. So it's, you know, remember I said that functions can take arguments or they can return and some functions take arguments and return. Some functions only take arguments. They don't return. Some functions do neither. Some functions do both. All these things are possible. So I'm trying to mix and match here. Okay. So return the conjugate. Okay, now what do we do? So how do we build up this conjugate? Well, we know that the real part doesn't change. So we can say conge.real. We can say that it's this.underscore.real. So we've set the real part of the conjugate to this.underscore.real. Now we need to set the imaginary part to be the opposite of our imaginary part. So if, if, let me see, if this.underscore.real is less than zero, else. I wish I could see the rule at the same time you were doing this. Can you drop that in as a comment? Well, the rule is, I guess that counts as a rule, doesn't it? Yeah, just to slash slash and paste that in for me, just. Okay, two plus three, I mean. Okay. So we're saying. Why would you need this? That's why I want to see it. Why do you need a test to see if it's less than zero? It's always going to be true. Yeah, so the real part just goes straight through, right? Doesn't matter. Why don't you just multiply it by negative one? You don't have to test it. You could just say. That's a really good idea. So kind of that imaginary, this is that imaginary times negative one. That's way easier than what I was going to do. Brilliant, yes, absolutely. Lazy, lazy, lazy, lazy. Oh, lazy good. Okay. So now we get to do the scary bit, test your code. So I did write down one I want you to do for the multiplication one. But that's okay. So, okay, so add is easy, subtract is easy. Multiply one, change that one to, wait, where are the two? Okay, so what you want to be the first number? The first one I want to be three plus four I. Three plus four I. And the second one make it two and minus six. Two plus four I and multiply by three. No, two and minus six. Two minus six. My siphon's correct. Oh, not the, oh, yeah, yeah, that's the one. All right. And what do you think the answer should be? I think it should be 30 minus 10 I. 30 minus. If it isn't, this is just wasted everybody's time. Okay, well, okay, so let's hit magic run button. Okay. Okay, so the first thing we're saying is make a new complex number and just say it. One comma two. One plus two I, okay, that's correct. Add four plus two I to our number. So we're saying my cn that add new complex number, four comma two. So five and four, that's one of four is five. Two and two is four. So that's correct. Subtract two plus I from our number. So that should become three plus three I, which it does. And you say the last one should be 30 minus 10 I and it is therefore our arithmetic functions work. We have now created actually usable complex numbers. We could do really cool stuff with the exception of division, which is evil. So now we could go do physics and electromagnetic. Yes, we could. Yes, we could. Wow. So we made it through, Bart. You made it through. And as I say, the point of this is to show you, well, I guess there's a couple of points. So the first is this is a pretty practical, pretty real world example of when you might want to create a custom data type. JavaScript does not understand complex numbers. So we have to explain it. And we have to explain all of it because JavaScript has no brain. It has no intelligence whatsoever. So we've got a point by point explained so that a complex number has two pieces. You can set the real piece to this, the imaginary piece to that. If you want it as a string, you do this. If you want to parse it, you do that. If you want to add it, you do this. Subtract to that, yada, yada, yada. You got to teach it everything. However, we have succeeded in so doing and we now have usable complex numbers. Very cool, Bart. We made it through it. I'm sure glad we did this in two pieces and now we're in 16 minutes later. Yeah, no, that was definitely, definitely. We probably, if I'd been thinking ahead, we probably should have broke the last one after part four. We are often ambitious in what we undertake, right? It's very hard to judge how long something would be in a conversation. Right, and I didn't even interrupt this much this time. I was pretty good. Excellent. Well, I think we have now laid ourselves a pretty darn solid JavaScript foundation. Wouldn't you agree? I would definitely agree. Whether I can execute much of it on my own, I'm not going to promise anything. Oh, I am going to make you fix one thing. It's been driving me crazy. Line six in the comments, value has got the A and the L switched. It's in your, it's in your, your thing online too. I noticed that like three weeks ago. I'll have to fix it for reals. So I still have to go through and finish Codecademy. I sort of stopped and played with a baby for a week instead of paying attention to this, I'm afraid. That seems like a reasonable thing to do. Yeah, it was a good idea. I think, right? So we're going to move on next time to moving into the browser. Even if all of this hasn't fully sunk in, enough of it has sunk in that the browser can start to motivate you. Yeah, having something to do. Exactly. Would be good. So I'm hoping that also in terms of the stuff we need in the browser, assignments one through four are like really, really, really, really, really important. And assignment five is much less important. Oh, good. Because I was way better at one through four. So if one through four are just absolutely hunky-dory fine, then we are absolutely ready to move into the browser. Oh, yay. And we'll be able to start. Yeah, we'll be able to start doing cool and useful things. I would like to do at least the first half of our next one on video for one very simple reason. I am going to write in the show notes some English describing the JavaScript console. But I think we get a lot of value out of showing the JavaScript console. OK. And the JavaScript console is, what is that? It is a part of the browser that is for programmers. So it's a part of the browser that a programmer can use to talk to himself. Or rather, to have his code talk to him or her. Basically, it allows us to do, so we're going to lose pbs.say. Because pbs.anything is the playground. There will be no playground. We are moving into the real browser. So if we want to output some information to ourselves to check something, to debug something, we need to write it somewhere else. And the place we write it to is something called the console. And it would be a wonderful function called console.log. So pbs.say console.log. And I want to just show you the console. Because the console allows us to see into our JavaScript variables and things. It's really cool. And I will write it down for the blog post that will be there in perpetuity. But I really do want to show it. And that's going to become our new home. That's going to become as important to us as the playground was. Good. As we start to play it on the web. So we didn't get any hate mail about doing this as video. So I think we achieved the objective by not cramming a giant 200 megabyte video file onto everybody's phones. But we did get the gentle suggestion, please don't turn this into a video show. So having both, I'm going to continue to read as much as possible and stop you and say things out loud as much as I possibly can to keep people being able to follow along with the audio. Well, to be honest, I think once we're done with the next installment, I think we're back to business as usual. I don't think there's any need for a video after that. I think we'll just be back to like we were for the HTML stuff. In fact, one of the things I'm going to have to teach you is a whole bunch more HTML. You've nobody had to make a button. You've nobody had to make a text input, had to make a dropdown. None of those things. I don't know any of that yet, Bart. Yeah, I've got to teach you all that because, well, you've got to put data into the computer, right? For the JavaScript to do cool stuff with the data. So we're going to need to learn how to do all those forums and do-dads in what sets. Lots of lots more fun to come. Oh, fantastic. All right, Bart. Well, I guess we're done for the next couple of weeks. I believe exactly a couple. All right, we'll talk to you again then. Okey-dokey. Until then, happy computing.