2021-04-20

Apr 21 In-Class Exercise Thread.

Please post your solutions to the Apr 21 In-Class Exercise to this thread.
Best,
Chris
Please post your solutions to the Apr 21 In-Class Exercise to this thread. Best, Chris

-- Apr 21 In-Class Exercise Thread
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)
<pre> 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]); } } </pre>

-- Apr 21 In-Class Exercise Thread
 
 
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)
<pre> function Cart(theGroceryList) { this.groceryList = theGroceryList this.prettyPrint = function() { this.groceryList.forEach(groceryItem => { console.log(@BT@${groceryItem.item} costs ${groceryItem.price}@BT@) }); } } 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() </pre>

-- Apr 21 In-Class Exercise Thread
function Cart(price_list){
 	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(price_list){ this.list = price_list; Cart.prototype.prettyPrint = function(){ document.write("<ul>"); this.list.forEach(item => document.write("<li>" + item + "</li>")); document.write("</ul>"); } }

-- Apr 21 In-Class Exercise Thread
    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)
function cart(groceries){ this.groceries = groceries; cart.prototype.prettyPrint = () => { this.groceries.map((item) => { document.writeln(@BT@<p>item: ${item[0]} price:${item[1]}</p>@BT@); }) } } grocery_list = new cart([['eggs', 2], ['milk', 3], ['bread', 10]]); grocery_list.prettyPrint();

-- Apr 21 In-Class Exercise Thread
function cart(groceriesPrices){ this.groceries = groceriesPrices[0] this.prices = groceriesPrices[1] this.listPrices = function(){ for(var i = 0; i < this.prices.length; i++){ console.log(this.groceries[i] +" : "+this.prices[i]) } } } var grocerylist = [["apple","orange","mango","banana"],[1,3,6,3]] myCart = new cart(grocerylist); myCart.listPrices()
(Edited: 2021-04-21)
<nowiki> function cart(groceriesPrices){ this.groceries = groceriesPrices[0] this.prices = groceriesPrices[1] this.listPrices = function(){ for(var i = 0; i < this.prices.length; i++){ console.log(this.groceries[i] +" : "+this.prices[i]) } } } var grocerylist = [["apple","orange","mango","banana"],[1,3,6,3]] myCart = new cart(grocerylist); myCart.listPrices() </nowiki>

-- Apr 21 In-Class Exercise Thread
function Cart ( procery, price) {
    this.procery = procery
    this.price = price 
    var prettyPrint = console.log ( procery + " is $" + price)
} Cart ("Table", 15)
Resource Description for Screen Shot 2021-04-21 at 4.10.46 PM.png
(Edited: 2021-04-21)
function Cart ( procery, price) { this.procery = procery this.price = price var prettyPrint = console.log ( procery + " is $" + price) } Cart ("Table", 15) ((resource:Screen Shot 2021-04-21 at 4.10.46 PM.png|Resource Description for Screen Shot 2021-04-21 at 4.10.46 PM.png))

-- Apr 21 In-Class Exercise Thread
 <!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>
<!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], "<br />"); } } 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>

-- Apr 21 In-Class Exercise Thread
inclass exercise function cart(grocery_prices) { for (var item in grocery_prices) { this.groceryList.concat(item); this.priceList.concat(grocery_prices[item]); } this.display = prettyPrint; } function prettyPrint() { for (var i = 0; i < this.groceryList.length; i++) { document.write(this.groceryList[i] + this.priceList[i] + ""); } } var grocery_prices = []; grocery_prices['eggs'] = 2.00; grocery_prices['milk'] = 3.00; grocery_prices['bread'] = 4.00; my_cart = cart(grocery_prices); my_cart.display();
(Edited: 2021-04-21)
<nowiki> <!DOCTYPE html> <html> <head> <title>inclass exercise</title> <meta charset="utf-8"/> </head> <body> <script> function cart(grocery_prices) { for (var item in grocery_prices) { this.groceryList.concat(item); this.priceList.concat(grocery_prices[item]); } this.display = prettyPrint; } function prettyPrint() { for (var i = 0; i < this.groceryList.length; i++) { document.write(this.groceryList[i] + this.priceList[i] + "<br/>"); } } var grocery_prices = []; grocery_prices['eggs'] = 2.00; grocery_prices['milk'] = 3.00; grocery_prices['bread'] = 4.00; my_cart = cart(grocery_prices); my_cart.display(); </script> </body> </html></nowiki>

-- Apr 21 In-Class Exercise Thread
<!doctype html> <html> <head> <title> test </title> <meta charset="utf-8" />
</head> <body> <script>
	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();
</script> </body> </html>
<!doctype html> <html> <head> <title> test </title> <meta charset="utf-8" /> </head> <body> <script> function cart(groceries, prices) { this.groceries = groceries; this.prices = prices; cart.prototype.prettyPrint = function() { document.write(this.groceries, "<br />"); document.write(this.prices, "<br />"); }; } var a = new cart("egg", "$5"); a.prettyPrint(); </script> </body> </html>
[ Next ]
X