1
00:00:00,270 --> 00:00:06,360
In this video we're going to introduce javascript methods and we're going to use three built in methods

2
00:00:06,540 --> 00:00:09,340
which will be useful for the next set of exercises.

3
00:00:09,340 --> 00:00:19,560
So those methods are alert prompt and console dialog and I'm going to go ahead and make this a little

4
00:00:19,560 --> 00:00:21,440
bit bigger here.

5
00:00:21,450 --> 00:00:27,990
One thing you'll notice is that I'm using javascript comments just like in CCS and in HCM all javascript

6
00:00:27,990 --> 00:00:34,320
has its own way of defining comments which is just notes and things that don't actually run and aren't

7
00:00:34,350 --> 00:00:35,130
executed.

8
00:00:35,130 --> 00:00:40,200
So we use double slashes and then whatever I put here won't actually be run.

9
00:00:40,230 --> 00:00:47,460
So if I did something like five plus 10 which normally would be 15 it just doesn't run it at all.

10
00:00:47,460 --> 00:00:49,390
So that's comments in javascript.

11
00:00:49,980 --> 00:00:54,750
I'm also going to show one quick thing here which you'll see me do occasionally which is Cleator my

12
00:00:54,760 --> 00:01:00,030
console and I type the words clear and follow it with open and close parentheses.

13
00:01:00,040 --> 00:01:07,020
And I hit enter you know what that will do is clear my console there so clear itself is something called

14
00:01:07,430 --> 00:01:08,490
a method.

15
00:01:09,000 --> 00:01:13,260
And we're going to spend a lot of time later in this class talking about method and writing our own

16
00:01:13,260 --> 00:01:14,540
functions and methods.

17
00:01:14,970 --> 00:01:20,790
But at their core there's some code that someone else wrote or that we wrote eventually but for now

18
00:01:20,910 --> 00:01:25,590
there are methods that come with javascript or pieces of code that come a javascript that I can recall

19
00:01:26,010 --> 00:01:27,330
and I can run.

20
00:01:27,330 --> 00:01:34,300
So think of it almost as a variable but rather than storing a piece of data like the string hello.

21
00:01:34,560 --> 00:01:38,440
It stores other javascript code which can be executed over and over.

22
00:01:38,550 --> 00:01:45,930
So there could be a hundred lines of javascript that when I write clear are being called Clear actually

23
00:01:45,930 --> 00:01:50,250
happens to be pretty simple but there are methods that will see and that we write that will be pretty

24
00:01:50,250 --> 00:01:50,990
long.

25
00:01:51,450 --> 00:01:57,390
So the first method we're going to touch on is called alert and alert is actually a little bit of noxious

26
00:01:57,390 --> 00:01:57,450
.

27
00:01:57,450 --> 00:02:02,070
What it does is it pops up a message to the user it alerts the user.

28
00:02:02,070 --> 00:02:06,980
So the syntax looks like this alert in parentheses.

29
00:02:06,990 --> 00:02:12,150
And then instead of the parentheses we pass in something that we want to be alerted.

30
00:02:12,660 --> 00:02:17,890
So I can put a message as a string like hello there.

31
00:02:18,570 --> 00:02:23,020
And if I hit enter I get this annoying pop up that says the page.

32
00:02:23,040 --> 00:02:30,290
Google says hello there but I could also give it a number.

33
00:02:31,650 --> 00:02:40,020
I could have it do a little bit of math in there like 9 teen or 198 times three and four or five and

34
00:02:40,020 --> 00:02:42,270
it will alert the result.

35
00:02:42,270 --> 00:02:47,850
So as I mentioned it's a little obnoxious but we're going to use it before we actually build apps that

36
00:02:47,850 --> 00:02:50,140
display things with each to mount the assess.

37
00:02:50,220 --> 00:02:55,920
We're going to build apps that just display alerts the next when I want to show is similar to alert

38
00:02:56,100 --> 00:02:58,110
except it's much less intrusive.

39
00:02:58,140 --> 00:03:01,030
It's called console dot log.

40
00:03:01,290 --> 00:03:05,690
And what this will do is print something to the javascript console.

41
00:03:05,730 --> 00:03:10,320
So if someone doesn't have the console open they'll never see it print.

42
00:03:10,500 --> 00:03:16,240
So it looks like this con. don't log parentheses and then give it something to print.

43
00:03:16,340 --> 00:03:26,020
So hello from the console and all it does is just print up that text.

44
00:03:26,610 --> 00:03:32,640
So just like alert you really only going to use cancel that log early on in this class as a way of printing

45
00:03:32,640 --> 00:03:33,990
things to ourselves.

46
00:03:34,050 --> 00:03:39,180
So not printing means to a user you would never expect your user to actually go into the console but

47
00:03:39,180 --> 00:03:40,920
just for our own purposes.

48
00:03:41,460 --> 00:03:43,640
And then the last one I want to show is a little different.

49
00:03:43,740 --> 00:03:51,090
It's called prompt and prompt is very useful for us early on because it lets us get input from a user

50
00:03:51,090 --> 00:03:51,770
.

51
00:03:51,870 --> 00:04:00,360
So I'll show you what it looks like prompt parentheses and then inside of the parentheses we give it

52
00:04:00,360 --> 00:04:02,630
some text to prompt the user with.

53
00:04:02,630 --> 00:04:07,420
So something like What is your name.

54
00:04:07,770 --> 00:04:10,880
And if we do that you'll see a pops up or something.

55
00:04:10,890 --> 00:04:11,550
What is your name.

56
00:04:11,550 --> 00:04:19,110
And then I can put I can type in my name and hit OK so I'll type something in here and I hit OK.

57
00:04:19,140 --> 00:04:24,130
And of course it doesn't do anything with that because we're not storing the value.

58
00:04:24,150 --> 00:04:32,700
So the second part of prompt is that I can store it in a variable so I can save var user name ECOs prompt

59
00:04:32,700 --> 00:04:34,550
.

60
00:04:34,620 --> 00:04:37,370
What is your name.

61
00:04:38,520 --> 00:04:40,390
And this will pop up again.

62
00:04:40,530 --> 00:04:42,380
I can type something in there.

63
00:04:42,810 --> 00:04:44,870
I'll do Rusty this time.

64
00:04:45,510 --> 00:04:46,710
OK.

65
00:04:46,730 --> 00:04:51,000
Now instead of user name I have Rusty.

66
00:04:51,000 --> 00:04:54,380
So we're going to use prompts to ask users for input.

67
00:04:54,630 --> 00:05:00,120
And again we wouldn't use this in a real production web site but for these early exercises it's nice

68
00:05:00,120 --> 00:05:03,240
to have some variable input coming from a user.

69
00:05:03,270 --> 00:05:08,280
So the next few videos we're going to build some simple exercises that actually get input from the user
