Front-end Web Development
Assignment for Week 8
- Create an HTML file. (Start with the HTML file in Assignment 1 as a basis. Feel free to skip the CSS creation/linking steps.)
- Create a JS file (a blank file with a
.js extension).
- Add a
<script> element as the last element of the <body> in the HTML file. Set its src attribute to the name of your JS file.
- In the JS file, declare a variable called
createName and assign a function to it:
- The function should accept two arguments,
first and last.
- It should return a string which is the concatenation of
first, a space, and last.
- Declare another variable called
askName and assign another function to it:
- In the function, declare a variable called
first, and assign to it the result of the prompt DOM function call, which should ask for your first name.
- Declare a variable called
last, and assign to it the result of another prompt call, which should ask for your last name.
- Declare a variable called
fullName, and assign to it the result of calling the createName function we created above, passing in the first and last variables.
- Call the
alert DOM function, making use of the fullName variable to tell the user what their full name is, e.g. Your name is John Smith!
.
- No
return command necessary.
- Call the
askName function.
Extra credit:
- In the HTML file, add an
id attribute to the <p> tag, and set it to "asker".
- Add a line to the JS file that passes in that
id value as a parameter of the document.getElementById function call, then sets its result's onclick property to the askName variable.
- If all goes well, clicking on the paragraph on your page should pop up first/last name prompts.
More extra credit:
- Modify
askName to keep asking for your name until your full name is Murray Stenson.
Solution