WDV221 Intro Javascript

Variables and Data Types - In Class Exercises

Please complete the following exercises on this page. When complete post the page to your WDV221 folder on the server. Make a link in your WDV221 Intro Javascript page for this assignment. Contact your instructor and demonstrate that you have completed the assignment.

Using Blackboard complete the In Class Exercise Assignment. Download your Homework project and being working on it with your remaining time.

For each exercise use a comment line to put the Exercise number within the script. Also place a short description of what the script is doing.

Part I

Create a runtime script on this page. Define the following variables in that script. What is the scope of all these variables?

1. Define a String variable call yourName. Put your name in the variable.

2. Define a Numeric variable called numberSold with a value of 37.

3. Define a Numeric variable called totalSales with a value of 123.45.

4. Define a variable called goodMonth. Assign it a boolean value of true.

5 Define a variable called annualSales. Do not assign it a value.

Part II

Create a new script element below this paragraph. In that runtime script output each of the variables using the document.write( ). Each output should be within its own <p> element. Show the exercise number with each output. Your output should look something like this:

42. The variable dogName contains: Spot

Part III

6. Create a function called displayNames( ). Define a String variable called friendsName. Put one of your friend's name in the variable. The function should use an alert to display the variable yourName from 1. above. It should then display friendsName within an alert. Note: What is the scope of the friendsName variable?

7. Use a button with an onclick event to call the displayNames( ) function.

8. Create a function called displayFriendsName( ). It should use an alert to display the friendsName variable. Will it work correctly? Why or Why not? Note: DO NOT put that variable in this function.

Part IV

9. Create a function called getName( ). Define a variable called inName within the function. Code a prompt within the function that will ask the user for a name. Store the name from the prompt in the inName variable. Use an alert( ) to display the name that was entered. Create a button and use an onclick event to run this function.