Week 4 Task 8

by Ken Wai Ooi

HTML

<script>
// Used to creaet an instance called shopper in function notation
var html = function(unitName) {

    this.unitName = unitName;
    
    // Method to add an item to the shopping cart
    this.addToCart = function(theUnitDetails) {this.cart.push(theItem);}

    // Method to return an invoice as a String
    this.invoice = function() {
        var str = "Schedule for Ken" + "\n\n" ,
              sum = 0;
          for (var i=0 ; i< this.cart.length; i++) {
             str += this.cart[i].description + " $" +  
                    this.cart[i].cost + "\n";
             sum += this.cart[i].cost;
             }
          str += "\ntotal: $" + sum;
          return str;
    }
}

// Item constructor
var unitDetails = function() {
    this.description = description;
    this.cost = cost;
}

// Create a new instance of a Shopper object
var shopper = new Shopper("Jane", "Doe", new Array());

// Add items to the shopper's cart
shopper.addToCart(new Item ("lamp",    50.00));
shopper.addToCart({description: "chair",  cost: 100.00});
shopper.addToCart(new Item ("chair",  100.00));
shopper.addToCart(new Item ("table", 1500.00));

alert (shopper.invoice());

                  
           
</script>