I'm trying to make my code output something like this:
orange: 4.1
apple: 3.84
melon: 3.06
subtotal: 11
tax: 0.88
total: 11.88
but It wont output anything
here it is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic Page</title>
</head>
<body>
<script>
var cart = [] //creates an empty array for now
function createGroceryItem(name, price, quantity) {
var grocery = {"name" : name, "price" : price, "quantity": quantity, "totalPrice": function() { return price * quantity }, "printOut" : printOut};
return grocery;
}
function printOut() {
console.log(this.name + " #" + this.quantity + " : " + this.totalPrice());
}
function printReceipt(item1, item2, item3){
var subtotal =
item1.totalPrice();
item2.totalPrice(),
item3.totalPrice();
var tax = subtotal*.08;
var total = subtotal + tax;
item1.printOut();
item2.printOut();
item3.printOut();
console.log("subtotal:" + subtotal + "tax:" + tax + "ntotal:" + total);
}
cart.push(createGroceryItem("oranges", .82, 5));
cart.push(createGroceryItem("apples", .64, 6));
cart.push(createGroceryItem("melons", 1.02, 3));
printReceipt(cart[0],cart[1],cart[2]);
</script>
</body>
</html>
orange: 4.1
apple: 3.84
melon: 3.06
subtotal: 11
tax: 0.88
total: 11.88
but It wont output anything
here it is:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Basic Page</title>
</head>
<body>
<script>
var cart = [] //creates an empty array for now
function createGroceryItem(name, price, quantity) {
var grocery = {"name" : name, "price" : price, "quantity": quantity, "totalPrice": function() { return price * quantity }, "printOut" : printOut};
return grocery;
}
function printOut() {
console.log(this.name + " #" + this.quantity + " : " + this.totalPrice());
}
function printReceipt(item1, item2, item3){
var subtotal =
item1.totalPrice();
item2.totalPrice(),
item3.totalPrice();
var tax = subtotal*.08;
var total = subtotal + tax;
item1.printOut();
item2.printOut();
item3.printOut();
console.log("subtotal:" + subtotal + "tax:" + tax + "ntotal:" + total);
}
cart.push(createGroceryItem("oranges", .82, 5));
cart.push(createGroceryItem("apples", .64, 6));
cart.push(createGroceryItem("melons", 1.02, 3));
printReceipt(cart[0],cart[1],cart[2]);
</script>
</body>
</html>