This assignment is due by the end of class today, and uses input and output methods in JavaScript.  As you did for the exercise assignments, you will need to create a very basic web page using Aptana, Dreamweaver, or Notepad.  You do not need to add any special features or formatting to the page, although you may. 

Once you have a functioning web page, you will add a JavaScript program in the <body> of the page, according to the following instructions:

  1. Remember that you need to begin and end your program with the <script> tags.
  2. Your page is going to be called "Adding and Concatenating"  For your <title>, put "ADDCO"
  3. As the first line in your program, create an alert that welcomes all visitors to your page. 
  4. As the second line in your program, use document.write to generate text welcoming visitors to Your Name's Adding and Concatenating Page, replacing Your Name's with your own first and last name.

**Javascript makes web pages dynamic -- they change based on interactions with the user.

In order to facilitate two-way communication (interaction – a relationship of mutual influence analogous to a conversation), we will need to be able to gather input from a user and to store that input in a variable so the program can remember it.  Then we can use that same variable again in an output statement.  Or we can apply processing to the variable -- we can change it in some way.  The two processing skills we will use in this program are addition and concatenation

  1. Declare a variable called first_name.  Remember the keyword you need is var.
  2. Write a prompt statement that asks for the user's first or given name, and assigns the user's answer to the variable first_name.
  3. Write a document.write statement that begins with, "Your first name is " and ends with the input value of the variable first_name.  You will need to use concatenation.
  4. Declare a variable called last_name.
  5. Write a prompt statement that asks for the user's last or family name, and assigns the answer to the variable last_name.
  6. Declare a variable called age.
  7. Write a prompt statement that asks, "How old are you, ________?", where the blank is replaced by the name of the user (input value of the variable first_name).  Assign the response to the variable age.
  8. Write the following statement: age=Number(age); 
    1. This is done because of the rule that data coming in from a prompt statement is always treated as string data.  We are going to add a value to this number, and we want to be sure it doesn't concatenate.  Remember that even if all data that comes in from a prompt statement is in the form of numbers, the program will still treat it as string data and will concatenate it unless you convert it by using the Number function given here or some other process.
  9. Write an alert that says, "PERSON is age years old.  Next year PERSON will be Y years old" where PERSON is replaced by the first and last name of the user (concatenation of the variables first_name and last_name -- try to get a space in between), age is replaced by the age (variable age), and is a calculated value of the variable Yage plus the number 1.   
    1. For example, if Derren Brown were the user, his input value for first_name would be "Derren".  His input value for last_name would be "Brown".  His input value for age would be "40".    The alert in this case would read "Derren Brown is 40 years old.  Next year Derren Brown will be 41 years old."
  10. Write another output statement of your choice, thanking the user for allowing us to enlighten him or her.
  11. Remember to put the </script> tag before the </body> tag.
  12. Save the document as Intro_Ex_1_yourname.html.
  13. When you are done call Sam or I over so that we can check your work.