[ Prev ]
2021-04-21

-- Apr 21 In-Class Exercise Thread
<!DOCTYPE html> <html> <head>
    <title></title>
    <meta charset="utf-8" />
</head> <body> <script>
  displayItem = function(item) {
    alert(item.name + ' : $' + item.price)
  }
  displayCart = function(cart) {
    cart.itemList.forEach(displayItem);
  }
  function cartItem (name, price) {
    this.name = name;
    this.price = price;
    this.display = displayItem;
  }
  function cart(itemList) {
    this.itemList = itemList;
    this.display = displayCart;
  }
  var myItems = [new cartItem('milk', 3.00), new cartItem('eggs', 2.55)]
  c = new cart(myItems)
  c.display(c)
</script> </body> </html>
(Edited: 2021-04-21)
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> </head> <body> <script> displayItem = function(item) { alert(item.name + ' : $' + item.price) } displayCart = function(cart) { cart.itemList.forEach(displayItem); } function cartItem (name, price) { this.name = name; this.price = price; this.display = displayItem; } function cart(itemList) { this.itemList = itemList; this.display = displayCart; } var myItems = [new cartItem('milk', 3.00), new cartItem('eggs', 2.55)] c = new cart(myItems) c.display(c) </script> </body> </html>

-- Apr 21 In-Class Exercise Thread
Cart.prototype.prettyPrint(){ list = this.groceryList; var i; for (i = 0;i < list.length; i++){ document.write(list[i] + "\n"); } } function Cart(groceries){ this.groceryList = groceries; }
<nowiki>Cart.prototype.prettyPrint(){ list = this.groceryList; var i; for (i = 0;i < list.length; i++){ document.write(list[i] + "\n"); } } function Cart(groceries){ this.groceryList = groceries; }</nowiki>

-- Apr 21 In-Class Exercise Thread
 <!doctype html>
 <html>
 <head>
 <meta charset="utf-8" />
 </head>
 <body>
 <script>
 
 function display_cart()
 {
     document.write("Groceries_items:", this.items, "
"); document.write("Groceries_prices:", this.prices, "
"); }
 function cart(groceries_items, groceries_prices)
 {
    this.items = groceries_items;
    this.prices = groceries_prices;
    this.display = display_cart;
 }
 var my_cart = new cart("Apple", "12");
 my_cart.display()
 </script>
 </body>
 </html>
(Edited: 2021-04-21)
<!doctype html> <html> <head> <meta charset="utf-8" /> </head> <body> <script> function display_cart() { document.write("Groceries_items:", this.items, "<br />"); document.write("Groceries_prices:", this.prices, "<br />"); } function cart(groceries_items, groceries_prices) { this.items = groceries_items; this.prices = groceries_prices; this.display = display_cart; } var my_cart = new cart("Apple", "12"); my_cart.display() </script> </body> </html>

-- Apr 21 In-Class Exercise Thread
function prettyPrint() {
   for(let i = 0; i<this.list[0].length; i++)
   {
      console.log(this.list[0][i], ":", this.list[1][i], "");
   }
}
function Cart(list) {
  this.list = list;
  this.prettyPrint = prettyPrint;
}
let cart = new Cart([["Milk","Ham","Orange","Banana"],["$4","$3","$1","$2"]]);
cart.prettyPrint();
(Edited: 2021-04-21)
function prettyPrint() { for(let i = 0; i<this.list[0].length; i++) { console.log(this.list[0][i], ":", this.list[1][i], ""); } } function Cart(list) { this.list = list; this.prettyPrint = prettyPrint; } let cart = new Cart([["Milk","Ham","Orange","Banana"],["$4","$3","$1","$2"]]); cart.prettyPrint();

-- Apr 21 In-Class Exercise Thread
<script> 
 
      function cart(groceries, prices){
        this.groceries = groceries;
        this.prices = prices;
          this.prettyPrint = function(){
              document.write("[" + this.groceries + "]" + "<br />");
              document.write("[" + this.prices + "]" + "<br />");
          }//function
      }//cart 
 
      foods= ["lettuce", "beef", "bread"];
      costs= ["$3", "$10", "$4"];
      aCart = new cart(foods, costs);
      aCart.prettyPrint(); 
 
    </script>
<pre><script> function cart(groceries, prices){ this.groceries = groceries; this.prices = prices; this.prettyPrint = function(){ document.write("[" + this.groceries + "]" + "<br />"); document.write("[" + this.prices + "]" + "<br />"); }//function }//cart foods= ["lettuce", "beef", "bread"]; costs= ["$3", "$10", "$4"]; aCart = new cart(foods, costs); aCart.prettyPrint(); </script> </pre>

-- Apr 21 In-Class Exercise Thread
function Cart(prices){
 	this.price_list = prices;
 	Cart.prototype.prettyPrint = function(){
 		document.write("<ul>");
 		this.price_list.forEach(item => document.write("<li>" + item + "</li>"));
 		document.write("</ul>");
 	}
 }
var cart_list = new Cart([['milk', 4], ['beef', 10], ['noodles', 5]]); cart_list.prettyPrint();
function Cart(prices){ this.price_list = prices; Cart.prototype.prettyPrint = function(){ document.write("<ul>"); this.price_list.forEach(item => document.write("<li>" + item + "</li>")); document.write("</ul>"); } } var cart_list = new Cart([['milk', 4], ['beef', 10], ['noodles', 5]]); cart_list.prettyPrint();

-- Apr 21 In-Class Exercise Thread
<pre>
  function cart(items) {
    this.groceries = items;
    
    function prettyPrint() {
      this.groceries.map(printIt)
    }
    function printIt(item) {
      document.writeln("<p>"+item[0]+": $"+item[1]+"</p>")
    }
  }
groceryItems = new cart([['steaks', 30], ['Shrimps', 15], ['potatoes', 4], ['corns', 5]]); groceryItems.prettyPrint();
<pre> function cart(items) { this.groceries = items; function prettyPrint() { this.groceries.map(printIt) } function printIt(item) { document.writeln("<p>"+item[0]+": $"+item[1]+"</p>") } } groceryItems = new cart([['steaks', 30], ['Shrimps', 15], ['potatoes', 4], ['corns', 5]]); groceryItems.prettyPrint();

-- Apr 21 In-Class Exercise Thread
Dat Nguyen function cart(items) { this.items = items; } function prettyPrint(item){ document.write(item['item'], ": "); document.write("$", item['price'], ""); } items = [ { 'item': 'apple', 'price': 2.99, }, { 'item': 'banana', 'price': 1.99, }, { 'item': 'strawberry', 'price': 4.99, }, ]; myCart = new cart(items); for (var i = 0; i < myCart.items.length; i++) { prettyPrint(myCart.items[i]); }
(Edited: 2021-04-21)
<nowiki><!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Dat Nguyen</title> </head> <body> <script type="text/javascript"> function cart(items) { this.items = items; } function prettyPrint(item){ document.write(item['item'], ": "); document.write("$", item['price'], "<br />"); } items = [ { 'item': 'apple', 'price': 2.99, }, { 'item': 'banana', 'price': 1.99, }, { 'item': 'strawberry', 'price': 4.99, }, ]; myCart = new cart(items); for (var i = 0; i < myCart.items.length; i++) { prettyPrint(myCart.items[i]); } </script> </body> </html></nowiki>

-- Apr 21 In-Class Exercise Thread
  <!DOCTYPE html>
  <html>
  <head>
    <title>Ajay Salh</title>
  </head>
  <body>
  <script type="text/javascript">
      function cart(groceries){
        this.groceries = groceries;
        cart.prototype.prettyPrint = () => {
          this.groceries.map((item) => {
            document.writeln(`<p>item: ${item[0]} price:${item[1]}</p>`);
          })
        }
      }
      list = new cart([['cookie', 1.00], ['chips', 2.00], ['bread', 4.00]]);
      list.prettyPrint();
  </script>
  </body>
  </html>
(Edited: 2021-04-21)
<!DOCTYPE html> <html> <head> <title>Ajay Salh</title> </head> <body> <script type="text/javascript"> 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@); }) } } list = new cart([['cookie', 1.00], ['chips', 2.00], ['bread', 4.00]]); list.prettyPrint(); </script> </body> </html>

-- Apr 21 In-Class Exercise Thread
function Cart(List) { this.list = List this.prototype.prettyPrint = function() { this.list.forEach((element) => { console.log(`${element.item} | ${element.price}`) }) } } function grocery(item, price) { this.item = item this.price = price } let groceries = [ new grocery('banana', 3.50) new grocery('eggs', 2.50) ] myCart = new Cart(groceries) myCart.prettyPrint()
(Edited: 2021-04-22)
<nowiki>function Cart(List) { this.list = List this.prototype.prettyPrint = function() { this.list.forEach((element) => { console.log(@BT@${element.item} | ${element.price}@BT@) }) } } function grocery(item, price) { this.item = item this.price = price } let groceries = [ new grocery('banana', 3.50) new grocery('eggs', 2.50) ] myCart = new Cart(groceries) myCart.prettyPrint()</nowiki>
[ Next ]
X