WDV221 Intro Javascript

Lab Exam #1

Please do your work inside this page. You are welcome to modify the html of this page as needed for the project.

1. Define a global variable called studentName and assign your name to the field.

2. Define a global variable called courseName and assign the course name "WDV221 Intro to Javascript" to the variable.

3. Define a global variable called totalSales and assign it an initial value of 0.

4. Create a runtime script that will display studentName as an H1 element and the courseName as an H2 element above the form.

Hello ! Welcome back to MyShoppingCart

Item Price:
Number Purchased:
Sale Price:
Sales Tax:

Total Sales:

5. Use javascript to display the value of the studentName variable where yourName is currently displayed.

6. Change one of the submit buttons to "Calculate Sale". Apply an event handler to call the computeCost function.

7. Change the other button to a reset button.

8. Create a function called computeCost. The computeCost function should do the following things:

  1. Create a local variable called itemPrice. Initialize it to zero. Take the information entered in the Item Price textfield and place it in the variable.
  2. Create a local variable called numberPurchased. Initialize it to zero Take the information entered in the Number Purchased textfield and place it in the variable.
  3. Create a local variable called salePrice.
  4. The function should multiply itemPrice * numberPurchased and assign it to salePrice.
  5. Display the value of salePrice in the textfield next to the words Sale Price:
  6. Use the combined operator to add salePrice to totalSales. This will be the running total for the order.
  7. Display the value of the totalSales variable next the words Total Sales:. Use .innerHTML to make this happen.

Note: Even if you do not complete the function make sure it runs without breaking. Partial credit will be given for any work that runs corectly.

Extra Credit: