WDV221 Intro Javascript

Unit-4 - Functions and the String Object


Please complete the following exercises on this page. When complete post this page to your server. Make a link in your WDV221 homework page for this assignment.

Submit this assignment on Blackboard. Please include a link to your homework page.


1. Define a global variable called firstName. Assign it an initial value of "".

2. Define a global variable called emailAddress and assign it the value of your DMACC email address.

NOTE: These variables should be available to any script on this page including within any functions since they have global scope.

3. Create a function called getName( ). The function will use a prompt to ask the user to enter a name. Store the result in the firstName variable. Create a button with an onclick event handler to activate this function.

4. Create a function called displayName( ). The function will use alert( ) to display the value stored in the firstName variable. Create a button with an onclick event handler to activate this function.

5. Create a function called getEmail( ). The function will use a prompt( ) to ask the user to input an email address. Store the input in the global variable emailAddress. Create a button with an onclick event handler to activate this function.

6. Create a function called displayEmailName( ). The function will display the name portion of the email address stored in the yourEmailAddress variable. Create a button with an onclick event handler to activate this function.

For example: Assign emailAddress variable a value of "aStudent@dmacc.edu". This function should return display "aStudent".

7. Create a function called displayEmailServer( ). The function will display the email server name after the @ symbol. Create a button with an onclick event handler to activate this function.

For example: Given the same value for emailAddress variable. This function should display "dmacc.edu". Do not include the @ symbol.