WEBVTT 0 00:00.480 --> 00:00.800 All right. 1 00:00.810 --> 00:06.090 So in this module we're going to cover strings in more detail and we're going to fully get to grips 2 00:06.390 --> 00:08.550 with this particular primitive data type. 3 00:08.550 --> 00:13.380 So previously we saw that we can combine strings using the plus sign. 4 00:13.500 --> 00:18.780 And this creates a single string using a special feature of programming called concatenation. 5 00:18.780 --> 00:24.810 Now you have to imagine that you're joining together everything that's inside a quotation mark and ignoring 6 00:24.900 --> 00:25.820 everything else. 7 00:25.830 --> 00:33.060 So "a" + " " + "b" becomes "a b" concatenated into a single string. 8 00:33.060 --> 00:39.570 Now let's try it out in practice. If we head over to Chrome and we open up our Developer Tools and we 9 00:39.570 --> 00:43.650 head over to our Sources and our Snippets, 10 00:43.650 --> 00:52.550 then we can start writing some code inside our index.js. So we can create an alert that says "hello" 11 00:54.360 --> 00:56.130 + "world". 12 00:56.130 --> 01:02.880 And this, when we run it, will show helloworld with no spaces in between. So we can add the space by either 13 01:02.910 --> 01:07.700 including it inside a string, so a string with a single space, 14 01:07.700 --> 01:10.140 and this would be "hello" " " "world", 15 01:10.350 --> 01:18.510 or we can have it where we have a "hello" + " world", and remember that it's only the parts that are 16 01:18.630 --> 01:21.820 inside the quotation marks that are combined. 17 01:22.470 --> 01:24.070 All right. So this is pretty easy. 18 01:24.090 --> 01:31.120 So I want to set you the challenge of creating a greeting message using variables and alerts. 19 01:31.260 --> 01:34.140 So I want you to start off with two variables. 20 01:34.230 --> 01:41.190 One is a message which is equal to Hello, and the other variable is called name, 21 01:41.190 --> 01:48.720 and you can set it to either your name, or you can set it to whatever the user enters in a prompt. 22 01:48.780 --> 01:56.580 Then I want you to write a single line of code where you can create a pop up or an alert that says something 23 01:56.580 --> 02:05.190 like, that combines or concatenates these two variables into a single string using these two variables 24 02:05.280 --> 02:08.010 rather than simply just typing the string out. 25 02:08.310 --> 02:12.490 So pause the video and complete this quick challenge. 26 02:13.290 --> 02:13.590 All right. 27 02:13.590 --> 02:15.200 So that's pretty easy. 28 02:15.210 --> 02:17.790 All we need to do is to create an alert. 29 02:17.940 --> 02:20.310 We add the message. 30 02:20.310 --> 02:23.760 Then we add some characters in between, so namely it'll be 31 02:23.820 --> 02:25.910 Hello there, 32 02:26.100 --> 02:32.090 and then we add the name that we are going to greet. 33 02:32.130 --> 02:34.650 And finally we close off our alert. 34 02:34.710 --> 02:40.380 Now the important thing here is that you remember to add the spaces between the message and the name 35 02:40.380 --> 02:41.370 variables. 36 02:41.370 --> 02:46.210 You could have done it this way or you could add another string that's simply a space as well. 37 02:46.230 --> 02:47.950 So did you get that right? 38 02:47.970 --> 02:53.750 If not, have a review of this lesson and have a play around with concatenation inside the Chrome Developer 39 02:53.760 --> 02:58.950 Tools. And in the next lesson we're going to cover another cool feature of strings which is how we can 40 02:58.950 --> 03:03.650 quickly find out the number of characters that are contained inside a single string. 41 03:03.870 --> 03:06.570 So for all of that, I'll see you on the next lesson.