JavaScript Basics Pt. 4 - The String-quel

JavaScript
Transcript

English (Auto-generated)

to javascript basics part for this is the string qu'il uh there's a bit more you can do with strings and I am a firm believer that being able to do something is a great way to learn it. So we're also gonna do a little exercise at the end of this just to get some of these things we've learned with strings a little more firmly planted in your heads. All right. So let's go ahead and dive right in. So a bit more you can do with the drinks. So there is something in Programming called zero Based Indexing. So javascript and a lot of other languages. Pretty much computers in general don't start counting it one like humans do. Uh, there's a lot of things you'll find with javascript and I'll get more into this. Uh, as we get more into different things you can do with logic and functions in javascript. Um, but you'll kind of have to change the way you think about things and like I said, we'll get more into that. But so one of those things is that you don't start counting at one in javascript, you start counting at zero. So I've got an example right here. You've got a string A B C D E F. If you want to get the A out of it. This is zero. This would be 1234 and five. So that is how that works. That is something important to know. Um um and it's known as well. Not known as, but when you, when you count or if you want to pull something out of a string or other types of data types, you use bracket notation. Uh And it's a method you can use to find the character in a string. Um And like I said, the music of the data types, but I think the best way for me to explain that is for me to show you, let's go ahead and do that. So you want to go ahead and open up rep lit? If you haven't already, I'll give you a second to do that. Uh And then you want to head into the script dot Js file, If you've already closed out, you don't have that previous environment you're working in. That's probably just go ahead and open up a new one. Head to the script dot Js file. And so here let's go ahead and make any variable called string. And people go ahead and do a B c d e f like we had before. So six bracket notation is going to be if we write down the variable name here, and then we use square brackets. So just pop that in. And then if we want to get the A out of it, you would put zero because that is the first place. You'll hit run, let me go ahead and make the council bigger focus right there. Hit run. It's going to give you a because that is the first character in that string A is at position zero. So if we want to get position F. We've got 1234566 characters in this. But you don't want to write six, you will want to write five because it's kind of a zero. So now we will pull f out of this and this may seem like it's a little thing. But bracket notation is something you'll use a lot, especially when we get to a raise and that's something for another lesson. But I'm showing you this now with strings because it is something that will be commonly used with lots of different data types and this seems like a good point to bring it up. Alright, that is bracket notation. And now the last little thing I wanted to do, she here this little thing I wanted to do was do a little exercise like I mentioned. So this is your time to shine. So we are going to make a mad lip and using what you've learned about variables. Strings, fix that variable strings and shrinking concatenation. I want you to make your very own mad lip if you're not familiar with that. That is where you have a phrase right now with blank spaces and then you fill those spaces of which words that you think would fit the phrase well. So we're gonna be using again variable strings and string concatenation to make that mad look. So some rules for this. I want it to have at least one down one adjective and one verb defined as variables. So you will go ahead and write those out. You can the easiest way to define those it's going to be you can just say comes around because oh contra verb equals Hey, that's how you can do that. So we just need them now. An adjective verb. You want to have at least one in there of each and then use concatenation to combine those variables with these words as your strings. So this is the phrase I want you to use the blank looked blank comma. But I really wish blank hadn't blanked it period. So again you want to use string concatenation. So you'll have these phrases as your strings and you don't want to remember with shrinking concatenation, how that works with spacing. So you want to account for spacing and then once you have your variables to find with your noun adjective verbs, you want to put this all together. Um So once you do this on your own, um give it a good shot because it's only going to help if you, you know if you can try it on your own. If not we are going to go do it together. So we'll go ahead and pause for a few seconds here and then uh we will go ahead and continue. You can follow along and watch me make one. Alright, so if you are now back with us. I am hoping that you give it a shot on your own. Uh You know whether or not you were able to do it right or it took you a few tribes or you weren't able to do it. We will go ahead and I'll walk you through how you would make your very own mad lip. Alright, so let's go ahead and so I wanted to have at least one now, another verb, one adjective, I'll have those up here, I will go and define those right now is blank strings. That's not bad. And then we will go and make this console log and in that council I will go and plug in this phrase just so we can kind of see what we are looking at here, what we're working with. So the blank looked blank but I really wish blank had linked it. All right, so let's go ahead and figure out. So it looks like we've got at least we've got three of these but we have four spaces so we want to figure out which one of these you want to double up on. Another thing I'm gonna do though, that's very easy is actually I'll say that let's go ahead and think of what we can put here let's see say the first now you know I'm using single quotes let's go ahead and use double quotes across the board that's for consistency and I forgot the assignment operator there. Oops, that's my bad. Alright, so let's say chili can be our very first now we can plug that in there. Let's say for verb it dropped, we can say delicious. And then let's go ahead and do another now. Okay. Oops, kevin, kevin will be our second now. All right now let's go and put the schedule. So it the right way. So we'll get rid of these underscores. And remember with drinking can't nation, it does not add the spaces for you because it will just print out exactly what you put. So let's say here vi you know what I mean? This name because we can't have two contests with the same name, se v the name. Oh no the noun and then we will you know what? I'm already forgetting that space. We want to put a space in front of looked as well. So again those spaces are important. So that's why this actually is important. So the blank looked or the noun looked and we'll pull again our adjective variable there and then we will do another string with the space and the comma because we want that. Okay, actually, you know what we're going to put this together. But I really wish so we will put the space comma. Actually no, no space in front of the kama. Uh and then we'll put the space after. Wish we'll get rid of this Three underscores right there to add in our second to last variable. And for this we'll plug in name. So I really wish name another plus sign, thinking cabinet and you want to put a space in front of the hadn't and then another space after hadn't another kurdish mark to finish out that piece of string, hadn't. And then now it's time for our final variable, which is the verb, the scientist and cagney and then you want to keep the space in front of it and it dropped it. Alright, let's go and print this out and see if we did it successfully. Oh, let's see what is the issue here. That was ironic. Mm hmm. Oh you know, missing plus sign there. Mhm huh. Let's see what the issue is. Why is it not liking this? I don't really see. All right, So let's let's run through the skillet so we have our variables to find up top. They're all defined or declared directly or correctly. Sorry, wow, it's not even that early in the morning for me. Um see the now I'm looked Yeah, yes, valid or expected token. So it's it's something on this line that it's oh you know what it is for some reason it is taking this as part of the string. I'm not quite sure why. Okay, I'm not sure why, but it was taking this at the end of the parentheses. It was included as part of the string. There's something wrong with this final quotation marks here. I think it's because I copied it over from the power point. There we go. Alright, little bug squashing their the chili look delicious, but I really wish kevin hadn't dropped it. Yeah, man kevin spent all night working on the chilly, offered just to end up on the office's floor ready for the reception. All right, well I hope you're able to do that on your own. If not, I hope you're able to follow along with me as I worked it out with you in a in real time. So that's something that's important to know. And again, I firmly believe in showing examples and doing examples and trying things out on your own because that's how you're going to learn. So we're going to be doing a lot of that in this course. But anyways, thank you so much for following along. I hope you're able to get it done on your own. If not, no worries. If you need to review those other sections, go for it. But other than that that is it for this lesson and I will see you in the next one
134 Views 1 Likes 0 Comments

More you can do with strings and our first exercise!

Comment
Leave a comment (supports markdown format)