function cart(grocery_prices) {
this.grocery_prices = grocery_prices;
cart.prototype.prettyPrint = function() {
for(var i=0; i<this.grocery_prices.length; i++) {
document.write(this.grocery_prices[i]);
}
}
(Edited: 2021-04-21)
function Cart(theGroceryList)
{
this.groceryList = theGroceryList
this.prettyPrint = function() {
this.groceryList.forEach(groceryItem => {
console.log(`${groceryItem.item} costs ${groceryItem.price}`)
});
}
}
function GroceryItem(theItem, thePrice) {
this.item = theItem
this.price = thePrice
}
let groceryList = [
new GroceryItem('Milk', '$3.50'),
new GroceryItem('Apples', '$0.50'),
new GroceryItem('Chips', '$2.00'),
new GroceryItem('Cereal', '$2.99')
]
let cart = new Cart(groceryList)
cart.prettyPrint()
(Edited: 2021-04-21) this.list = price_list;
Cart.prototype.prettyPrint = function(){
document.write("<ul>");
this.list.forEach(item => document.write("<li>" + item + "</li>"));
document.write("</ul>");
}
}
function cart(groceries){
this.groceries = groceries;
cart.prototype.prettyPrint = () => {
this.groceries.map((item) => {
document.writeln(`<p>item: ${item[0]} price:${item[1]}</p>`);
})
}
}
grocery_list = new cart([['eggs', 2], ['milk', 3], ['bread', 10]]);
grocery_list.prettyPrint();
(Edited: 2021-04-21)
this.procery = procery
this.price = price
var prettyPrint = console.log ( procery + " is $" + price)
<!DOCTYPE html>
<html>
<head>
<title>inclass exercise</title>
<meta charset="utf-8"/>
</head>
<body>
<script>
function prettyPrint()
{
for(i = 0; i<this.groceries_prices[0].length; i++)
{
document.write(this.groceries_prices[0][i], ": ", this.groceries_prices[1][i], "
");
}
}
function Cart(groceries_prices)
{
this.groceries_prices = groceries_prices;
this.prettyPrint = prettyPrint;
}
arr = [["Tomato","Potato","Apple","Banana"],["$3","$5","$1","$2"]]
var cart = new Cart(arr);
cart.prettyPrint();
</script>
</body>
</html>
function cart(groceries, prices)
{
this.groceries = groceries;
this.prices = prices;
cart.prototype.prettyPrint = function()
{
document.write(this.groceries, "
");
document.write(this.prices, "
");
};
}
var a = new cart("egg", "$5"); a.prettyPrint();