In this video we're going to introduce javascript methods and we're going to use three built in methods
which will be useful for the next set of exercises.
So those methods are alert prompt and console dialog and I'm going to go ahead and make this a little
bit bigger here.
One thing you'll notice is that I'm using javascript comments just like in CCS and in HCM all javascript
has its own way of defining comments which is just notes and things that don't actually run and aren't
executed.
So we use double slashes and then whatever I put here won't actually be run.
So if I did something like five plus 10 which normally would be 15 it just doesn't run it at all.
So that's comments in javascript.
I'm also going to show one quick thing here which you'll see me do occasionally which is Cleator my
console and I type the words clear and follow it with open and close parentheses.
And I hit enter you know what that will do is clear my console there so clear itself is something called
a method.
And we're going to spend a lot of time later in this class talking about method and writing our own
functions and methods.
But at their core there's some code that someone else wrote or that we wrote eventually but for now
there are methods that come with javascript or pieces of code that come a javascript that I can recall
and I can run.
So think of it almost as a variable but rather than storing a piece of data like the string hello.
It stores other javascript code which can be executed over and over.
So there could be a hundred lines of javascript that when I write clear are being called Clear actually
happens to be pretty simple but there are methods that will see and that we write that will be pretty
long.
So the first method we're going to touch on is called alert and alert is actually a little bit of noxious
.
What it does is it pops up a message to the user it alerts the user.
So the syntax looks like this alert in parentheses.
And then instead of the parentheses we pass in something that we want to be alerted.
So I can put a message as a string like hello there.
And if I hit enter I get this annoying pop up that says the page.
Google says hello there but I could also give it a number.
I could have it do a little bit of math in there like 9 teen or 198 times three and four or five and
it will alert the result.
So as I mentioned it's a little obnoxious but we're going to use it before we actually build apps that
display things with each to mount the assess.
We're going to build apps that just display alerts the next when I want to show is similar to alert
except it's much less intrusive.
It's called console dot log.
And what this will do is print something to the javascript console.
So if someone doesn't have the console open they'll never see it print.
So it looks like this con. don't log parentheses and then give it something to print.
So hello from the console and all it does is just print up that text.
So just like alert you really only going to use cancel that log early on in this class as a way of printing
things to ourselves.
So not printing means to a user you would never expect your user to actually go into the console but
just for our own purposes.
And then the last one I want to show is a little different.
It's called prompt and prompt is very useful for us early on because it lets us get input from a user
.
So I'll show you what it looks like prompt parentheses and then inside of the parentheses we give it
some text to prompt the user with.
So something like What is your name.
And if we do that you'll see a pops up or something.
What is your name.
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.
And of course it doesn't do anything with that because we're not storing the value.
So the second part of prompt is that I can store it in a variable so I can save var user name ECOs prompt
.
What is your name.
And this will pop up again.
I can type something in there.
I'll do Rusty this time.
OK.
Now instead of user name I have Rusty.
So we're going to use prompts to ask users for input.
And again we wouldn't use this in a real production web site but for these early exercises it's nice
to have some variable input coming from a user.
So the next few videos we're going to build some simple exercises that actually get input from the user