This lesson is going to be a challenge lesson where we're going to take something that we've learned
earlier and apply it to something new, and then you think that we're introducing and the lesson is
a template literal, so allows you to use the tactics.
So that's just above your tab on your keyboard or to the left of the one key on your keyboard or most
keyboards.
And you can use these tactics in order to wrap the content of your template.
And there's some examples as well available at the Mozilla Developer Network.
And as well, we already got introduced to prompt, which gives us the ability to to show an input to
the user and then use that input value, returning it into a variable and then utilize that variable
within the code.
So let's take a look at template literals called temperate strings prior to its 2015 specification.
And you can see we've got the tactics and the wrapping the content, and they're allowing us to have
line breaks in there as well.
Calculate some JavaScript.
So we've got a variable of A and a variable of B, so it allows us to add those together.
So typically before the template literals or when we're using the quotes, the single quotes, we see
that we have to break out of the quotes and whereas done in a template literal, it's a whole lot neater.
And whenever we do have the line breaks, we don't have to do the back again.
In order to have a line break within our console, we can simply output that simply as having that line
break there.
So what you can do is you can copy this and we can go to inspect, go over to the console and paste
it in.
And we see that we get that output and that line break is included.
We need to have this all on one line within that expression and we can get the same output, but it's
not as nice and clean.
So the objective of this lesson, the challenge of this lesson is use a template literal in order to
pull the variable value in, ask the person the name and then use that variable that gets returned as
a template literal and then output the message.
So go ahead and try that in your editor.
So we need a variable in order to contain our user name.
And we're going to collect this using the prompt, asking what is your name to the Web visitor?
And then we'll also going to create a message variable and this is going to use a template literals.
So we've got our back.
And you can also enter in a line break if you want to as well, to utilize the variable.
We use the dollar sign and the curly brackets.
And here we just simply put in the name of the variable and we close the statement with the semicolon
and now we can console log out message and also it gets returned.
So when we refresh, it's asking us for our name.
And we see we've got welcome, Lawrence.
So if, for instance, we want it to have the name on the second line, you can see that the way that
it works, it outputs it within the same format.
So we don't have to have the backslash for the line break or anything like that that we normally would
with the single quotes.
So go ahead and try this out within your editor.