1 00:00:00,802 --> 00:00:04,870 All right, you've learned three different ways to output messages with JavaScript, 2 00:00:04,870 --> 00:00:08,140 a dialog box, writing directly to the console, and 3 00:00:08,140 --> 00:00:09,880 writing to the current web page. 4 00:00:09,880 --> 00:00:13,964 Let's put these pieces together and write a small program using these three methods. 5 00:00:13,964 --> 00:00:16,676 If necessary, clear the console to add new code. 6 00:00:16,676 --> 00:00:20,600 First, type alert. 7 00:00:20,600 --> 00:00:26,200 And in between quotation marks, type the message Hello. 8 00:00:26,200 --> 00:00:26,900 Thanks for visiting. 9 00:00:30,620 --> 00:00:36,010 Now, I don't want to run this code yet, so I'll press and hold down the shift key. 10 00:00:36,010 --> 00:00:40,746 Then press enter to bring the cursor down to the next line without running the code. 11 00:00:40,746 --> 00:00:46,500 Next, type console.log and 12 00:00:46,500 --> 00:00:51,670 provide it the message, Hello from the console between quotation marks. 13 00:00:55,600 --> 00:01:00,530 I'll again press Shift+Enter to bring the cursor down to the next line. 14 00:01:00,530 --> 00:01:04,774 And this time type document.write. 15 00:01:04,774 --> 00:01:11,197 And here's something interesting, you can even provide document.write markup or 16 00:01:11,197 --> 00:01:15,940 HTML tags containing the element and text to write to the page. 17 00:01:15,940 --> 00:01:17,270 h1 tags for example. 18 00:01:18,890 --> 00:01:24,070 In between the h1 tags I will write the message welcome to my web page. 19 00:01:26,750 --> 00:01:27,610 And that's it. 20 00:01:27,610 --> 00:01:31,620 You can also copy these lines of code from the teacher's notes with this video. 21 00:01:31,620 --> 00:01:34,230 So now we have three lines of code, 22 00:01:34,230 --> 00:01:38,000 which we can run by pressing the Enter or Return key. 23 00:01:38,000 --> 00:01:41,030 First, the alert dialog displays. 24 00:01:41,030 --> 00:01:45,170 After clicking OK, the message appears in the console and 25 00:01:45,170 --> 00:01:47,950 the welcome heading appears on the page. 26 00:01:47,950 --> 00:01:50,430 There are two things to understand from this. 27 00:01:50,430 --> 00:01:56,190 First, a program is a set of statements that run one after the other. 28 00:01:56,190 --> 00:02:02,260 Second, one statement needs to complete before the next statement runs. 29 00:02:02,260 --> 00:02:07,088 For example, the console.log command which prints to the console 30 00:02:07,088 --> 00:02:12,140 can't do its thing until the first alert command finishes. 31 00:02:12,140 --> 00:02:16,190 This also includes the user closing the dialogue box. 32 00:02:16,190 --> 00:02:21,715 Once that happens, the console.log statement runs and finally document.write. 33 00:02:24,580 --> 00:02:27,970 Keep in mind that you won't often use alert or 34 00:02:27,970 --> 00:02:30,790 even document.write in your projects. 35 00:02:30,790 --> 00:02:34,990 I'm just using these commands now as quick and simple ways to produce some 36 00:02:34,990 --> 00:02:37,980 output as you learn the basics of the JavaScript language. 37 00:02:37,980 --> 00:02:41,110 You're also going to learn other common methods for running JavaScript and 38 00:02:41,110 --> 00:02:43,970 getting output when you're further along in your learning journey. 39 00:02:43,970 --> 00:02:47,360 All right, you've started your JavaScript programming adventure, 40 00:02:47,360 --> 00:02:50,510 written your first program, and learned new commands. 41 00:02:50,510 --> 00:02:55,210 In the next video, you'll learn where and how to add JavaScript to web pages.