[ Prev ]
2020-11-04

-- Nov 4 In-Class Exercise Thread
function cart(new_item, new_price){ this.item = new_item; this.price = new_price } cart.prototype.display = cart; my_list1 = new cart ("Milk", "3.99"); my_list2 = new cart ("Chocolate", "2.99"); my_list3 = new cart ("Soda", "1.99"); my_list1.display(); cart.prttyprint() = function { document.write("Item:" , this.item) document.write("Price:" , this.price) }
(Edited: 2020-11-04)
<nowiki>function cart(new_item, new_price){ this.item = new_item; this.price = new_price } cart.prototype.display = cart; my_list1 = new cart ("Milk", "3.99"); my_list2 = new cart ("Chocolate", "2.99"); my_list3 = new cart ("Soda", "1.99"); my_list1.display(); cart.prttyprint() = function { document.write("Item:" , this.item) document.write("Price:" , this.price) }</nowiki>

-- Nov 4 In-Class Exercise Thread
function prettyPrint() {
	document.write("Item:", this.item);
	document.write("Price:", this.price);
}
function cart(new_item, new_price) {
        this.item = new_item;
	this.price = new_price;
}
	cart.prototype.display = prettyPrint;
	cart1 => new cart("Apple", "1.00")
	cart1 => cart1.display();
(Edited: 2020-11-05)
function prettyPrint() { document.write("Item:", this.item); document.write("Price:", this.price); } function cart(new_item, new_price) { this.item = new_item; this.price = new_price; } cart.prototype.display = prettyPrint; cart1 => new cart("Apple", "1.00") cart1 => cart1.display();
2020-11-09

-- Nov 4 In-Class Exercise Thread
<!DOCTYPE html>
<html>
    <head>
        <title>Cart Thingy</title>
    </head>
    <body>
        <script type="text/javascript">
            function Cart(items, prices){
                this.items = items;
                this.pries = prices;
                Cart.prototype.prettyPrint = function(){
                    document.write("<table><tr><th>Items</th><th>Prices</th></tr>");
                    for (let i = 0; i < this.items.length; i++){
                        document.write("<tr><td>" + items[i] + "</td><td>" + prices[i] + "</td></tr>");
                    }
                    document.write("</table>");
                }
            }
            var test = new Cart(["Bread", "Cheese"], [1, 2]);
            test.prettyPrint();
        </script>
    </body>
</html>
(Edited: 2020-11-09)
<pre><!DOCTYPE html> <html> <head> <title>Cart Thingy</title> </head> <body> <script type="text/javascript"> function Cart(items, prices){ this.items = items; this.pries = prices; Cart.prototype.prettyPrint = function(){ document.write("<table><tr><th>Items</th><th>Prices</th></tr>"); for (let i = 0; i < this.items.length; i++){ document.write("<tr><td>" + items[i] + "</td><td>" + prices[i] + "</td></tr>"); } document.write("</table>"); } } var test = new Cart(["Bread", "Cheese"], [1, 2]); test.prettyPrint(); </script> </body> </html></pre>
X