WDV221 Intro Javascript

Calculations and Textfields - In Class Exercise 3

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.

Part I

Create three variables called v1, v2 and v3 with the following values: 3, 4, "8.3";

For exercises 1-6 use a document.write to display the resutls to the page. Include the exercise description in each line of output.

3. Multipy v1 and v2

4. Multiply v2 and v3

5. Add v1 and v3. Convert v3 using a parseInt( )

6. Add v1 and v3. Convert v3 using a parseFloat( )

7. Use a prompt( ) to get a new value for v3. NOTE: A prompt( ) ALWAYS returns a String even if you type in a number

9. Use a prompt( ) and a new value for v3. Use a parseFloat( ) to make sure the value from the prompt( ) is a number before you store it in v3.

Part II

11. Create a variable called count. Display count++ five times. This is a post-fix operator

12. Create a variable called count1. Display ++count five times. This is a pre-fix operator.

Part III

13. Use a document.write( ) to write the following equation using the += combined operator. sales = sales + newSales.

14. Use a documnet.write( ) to write the following equation using the -= combined operator. balance = balance - credit.

Part IV

15.Create a function called randomNumber( ). The function should create a random number from 1-10. It will display the number in an alert. Use an event handler on the button below to call the function.

Use the given textfield and the buttons below for the following exercises.

Number:

16. Make a function called displayNumber( ) that is activated from the Display Number button. This button will display the value of the textfield in an alert.

17. Make a function called inputNumber( ) that is activated from the Input Number button. This button will use a prompt( ) to get a number from the user and place it into the value of the textfield.