Welcome to our quick lesson about the JavaScript prompt, and this is going to be a lesson that is going
to show you how you can create interaction with the user and also get information from that Web user
and also why you need variables and a great example of what you can contained within a variable so called
example of the prompt, similar to the alert, except it asks you a question and allows the user in
order to respond.
So that's the big difference there.
And just like alert, you don't need to add window in front of it.
And of course you can if you want to, but it's going to be the same thing as the alert.
So the objective here is to add a variable using a prompt and create that variable from the response
from the user and then output utilize that variable that came in from the prompt into the console.
So we're going to write Welcome to my site.
And the prompt is going to be asking for the user's name and it's going to be adding in a message which
is going to be welcome to my site.
And then all we're doing is using that variable and outputting it into the console.
So great use of great example of how to use variables.
And this is a quick peek at the code that we're going to be writing.
So go ahead and pause the video.
And coming up next, I'll show you the solution.
The solution for this is to pick a variable name and we can just call it user name.
So we're using prompt.
And just a quick example of what prompt does.
So just like what we saw with the alert, you can type a message here within the rounded brackets.
And when you initialize that, you see that we get the popup, but it's different than the alert because
it's got an input here area here.
And if I type in a response, you're going to see that response gets returned back.
So the same idea here.
Whenever we use the prompt, then the response is going to get returned back as the value of the user
name.
So let's ask our question.
What is your name?
And as we progress through the course, there are better ways to create that user interaction and prompt
really isn't used a whole lot.
But we're just using that as a quick example of how to get a value into a variable and then utilize
that value.
So we're going to have another variable that we're setting up and this is going to be our message.
And then we're consoling, logging out this information.
So we've got our message first and we use the plus sign to concatenate a string with a user or with
two variables together so we can do plus to concatenate it together.
I'm going to just leave a space in there.
So let's try that.
It's only refresh.
What is your name?
So type in your name.
If your name is Lawrence, you can type that in.
Or you could use Lowrance if you want to come to my site.
Lawrence So there we go.
So try that.
It's and coming up next, I'll show you a better way to do this, using a template literal.