1 00:00:00,690 --> 00:00:03,830 Now that we have a method for collecting and storing information. 2 00:00:03,830 --> 00:00:08,060 Let's see how to use variables to display different messages in an alert box. 3 00:00:08,060 --> 00:00:10,300 I'll use variable together with the prompt and 4 00:00:10,300 --> 00:00:13,990 alert to create a simple program that ask the user for their name and 5 00:00:13,990 --> 00:00:17,020 replies with a short message that displays their name. 6 00:00:17,020 --> 00:00:23,830 So in a console, I create a new variable named response to store and 7 00:00:23,830 --> 00:00:28,400 remember the response, or what a user types into the prompt dialogue box. 8 00:00:28,400 --> 00:00:33,640 So I'll set the value to prompt, passing it the variable question. 9 00:00:34,990 --> 00:00:38,810 Now I'll press Shift+Enter to bring the cursor down. 10 00:00:38,810 --> 00:00:43,520 And below the response variable, I'll add alert and 11 00:00:43,520 --> 00:00:46,190 pass it the message to display as a string. 12 00:00:46,190 --> 00:00:51,980 So the message will be Hello, followed by the users name and an exclamation mark. 13 00:00:51,980 --> 00:00:57,020 So the response variable is going to hold the value of what the user types 14 00:00:57,020 --> 00:01:01,130 into the box as a string, so to combine the word hello and 15 00:01:01,130 --> 00:01:04,980 the exclamation mark with what the user types into the dialogue box. 16 00:01:04,980 --> 00:01:10,340 I'll first type Hello and a space between quotes, 17 00:01:10,340 --> 00:01:13,835 followed by a plus sign, and the response variable. 18 00:01:15,275 --> 00:01:17,785 Then to add the exclamation mark at the end, 19 00:01:17,785 --> 00:01:23,325 I'll type a plus sign followed by the exclamation mark inside quotes. 20 00:01:23,325 --> 00:01:26,165 So here, I'm combining strings 21 00:01:26,165 --> 00:01:30,690 using the plus sign which is a common way of joining two or more strings together. 22 00:01:30,690 --> 00:01:34,210 Combining strings together like this is called concatenation. 23 00:01:34,210 --> 00:01:38,580 It's JavaScript's way of adding strings together to create a bigger string. 24 00:01:38,580 --> 00:01:42,200 So now I'll press Enter to run this program and 25 00:01:42,200 --> 00:01:47,530 in the browser, I first see the prompt dialog box asking, what is your name. 26 00:01:47,530 --> 00:01:49,970 I'll type Guil and click OK. 27 00:01:51,030 --> 00:01:54,350 Then I get the alert box with the message, Hello Guil!, good.