So let's go ahead and create the solution to this javascript stocker exercise.
So I have a stalker.
Each time I'll file and I'm going to fill it out with my basic boiler plate.
Give it a title
and let's put a simple H-1 J.S. stocker solution just so that we can see the page load.
Now I'm going to make my javascript file new file.
I'm going to save it and I'll just call it script.
Us in the same directory.
And I'm just going to put a console log in here just to make sure it works.
Cancel that log from the script file and save.
Now let's go open this in the browser.
We won't see anything unless they open the console and I still don't see anything because I haven't
connected my files so that's the next part I'm going to go here.
I had my script Reg source equals script dot J.S. make sure those match script js script.
Yes go refresh the page.
Now I get my constant log from the script file.
So now let's work on the logic here.
So the very first thing that needs to happen we need to ask for the first name.
So I'm going to set a variable first name because prompt.
What is your first name
and save.
And then do the same thing for a last name.
Last name prompt.
What is your last name.
And lastly the same thing for.
Age.
What is your age and save so that will get those three pieces of data and you can see that here if I
refresh it asked me three times and then it doesn't do anything with that.
So now we want to print out the form name so that's a con. But log.
Not an alert because we don't want to pop up just to cancel that log.
And let's make the string here your full name is and then make sure we have the space here plus first
name and let's just start with that and see what we get.
So I'll refresh the page rusty steel 3.
Your full name is Rusty.
OK so that's working.
Now we just want to add in last name but remember we need the space here because this will just take
Rusty and steel and smushed them together.
So to do that we can just add in a string.
That's all it is is a space.
So your full name is space first name plus space plus last name.
And if we run this and refresh rusty steel 3.
Your full name is rusty steel.
Next up we're going to print out the age so that's another council about log you are plus age plus we
use space afterwards.
Years old just like that.
So you are space age space years old and if we run this now and refresh rusty steel 3.
Your full name is rusty steel.
You are three years old and that's it.
There is one small change that we could make so you could argue that this is a little bit clunky here
.
So it's kind of cluttered.
So we could just pull this out into its own variable.
So I'm going to cut that out and just make a variable called full name and set it equal to that value
of first name plus space plus the value of last name.
And then here I can just print full name.
So this is just a matter of preference.
It's not right or wrong it's just whatever you think looks better.
And I happen to think this is nicer because now we have this full name variable that has the entire
file name stored in it.
So just to prove to you nothing changed I refresh Rustie still 3 and we get the same output.