[ Prev ]
2021-04-22

-- Apr 21 In-Class Exercise Thread
<!doctype html> <html>
<head>
    <meta charset="utf-8" />
</head>
<body>
    <script>
        function prettyPrint() {
            document.write("Groceries Prices:", this.prices, "");
        }
        function cart(groceries_prices) {
            this.prices = groceries_prices;
            this.print = prettyPrint;
        }
        var myCart = new cart("Bread", "$3");
        myCart.print()
    </script>
</body>
</html>
<!doctype html> <html> <head> <meta charset="utf-8" /> </head> <body> <script> function prettyPrint() { document.write("Groceries Prices:", this.prices, ""); } function cart(groceries_prices) { this.prices = groceries_prices; this.print = prettyPrint; } var myCart = new cart("Bread", "$3"); myCart.print() </script> </body> </html>

-- Apr 21 In-Class Exercise Thread
var grocery_items = ["apple", "bread", "milk"]; var grocery_prices = ["1.00", "6.00","4.50"];
function Cart(grocery_items, grocery_prices){
    this.grocery_items = grocery_items;
    this.grocery_prices = grocery_prices;
    Cart.prototype.listGroceries = function() {
        for (i = 0; i < grocery_items.length; i++) {
            console.log("grocery item : ", this.grocery_items[i], 
            "price : $", this.grocery_prices[i]);
        }
    }
}
var grocery_items = ["apple", "bread", "milk"]; var grocery_prices = ["1.00", "2.00","3.00"] var grocery_cart = new Cart(grocery_items, grocery_prices) grocery_cart.listGroceries();
var grocery_items = ["apple", "bread", "milk"]; var grocery_prices = ["1.00", "6.00","4.50"]; function Cart(grocery_items, grocery_prices){ this.grocery_items = grocery_items; this.grocery_prices = grocery_prices; Cart.prototype.listGroceries = function() { for (i = 0; i < grocery_items.length; i++) { console.log("grocery item : ", this.grocery_items[i], "price : $", this.grocery_prices[i]); } } } var grocery_items = ["apple", "bread", "milk"]; var grocery_prices = ["1.00", "2.00","3.00"] var grocery_cart = new Cart(grocery_items, grocery_prices) grocery_cart.listGroceries();
2021-04-25

-- Apr 21 In-Class Exercise Thread
Emily Chan: April 21 Exercise displayItem = function(item) { document.write(item.name + ': $' + item.price + '') } displayCart = function(cart) { cart.shoppingList.forEach(displayItem); } function cartItem (name, price) { this.name = name; this.price = price; this.display = displayItem; } function cart(shoppingList) { this.shoppingList = shoppingList; this.display = displayCart; } var groceries = [ new cartItem('Almond Milk', 3.00), new cartItem('Chocolate Chips', 5.00), new cartItem('Cocoa Powder', 6.50) ] myCart = new cart(groceries) myCart.display(myCart)
<nowiki><!DOCTYPE html> <html> <head> <title>Emily Chan: April 21 Exercise</title> <meta name="author" content="Emily Chan"> <meta charset="utf-8"> </head> <body> <script> displayItem = function(item) { document.write(item.name + ': $' + item.price + '<br>') } displayCart = function(cart) { cart.shoppingList.forEach(displayItem); } function cartItem (name, price) { this.name = name; this.price = price; this.display = displayItem; } function cart(shoppingList) { this.shoppingList = shoppingList; this.display = displayCart; } var groceries = [ new cartItem('Almond Milk', 3.00), new cartItem('Chocolate Chips', 5.00), new cartItem('Cocoa Powder', 6.50) ] myCart = new cart(groceries) myCart.display(myCart) </script> </body> </html> </nowiki>

-- Apr 21 In-Class Exercise Thread
function cart(groceriesAndPrices){
    this.groceries = groceriesAndPrices[0]
    this.prices = groceriesAndPrices[1]
    this.prettyPrint = function(){
    
    	var i = 0;
        for(i = 0; i < this.prices.length; i++){
            console.log(this.groceries[i] + ": $" + this.prices[i])
        }
    }
}
var grocerylist = [["Potato", "Eggs", "Fish", "Tomatoes", "Apple", "Eggplant"],[1, 3, 6, 3, 8, 10]];
myCart = new cart(grocerylist); myCart.prettyPrint();
(Edited: 2021-04-25)
function cart(groceriesAndPrices){ this.groceries = groceriesAndPrices[0] this.prices = groceriesAndPrices[1] this.prettyPrint = function(){ var i = 0; for(i = 0; i < this.prices.length; i++){ console.log(this.groceries[i] + ": $" + this.prices[i]) } } } var grocerylist = [["Potato", "Eggs", "Fish", "Tomatoes", "Apple", "Eggplant"],[1, 3, 6, 3, 8, 10]]; myCart = new cart(grocerylist); myCart.prettyPrint();

-- Apr 21 In-Class Exercise Thread
function Cart(groceryList) {
  this.groceries = groceryList
  this.prettyPrint = function() {
    this.groceries.forEach(item => {
      console.log(`${item.item} costs ${item.price}`)
    });
  }
}
 
function GroceryItem(item, price) {
  this.item = item
  this.price = price
}
 
let groceries = [
  new GroceryItem('Oreos', '$3.20'),
  new GroceryItem('Chocolate Cake', '$5.10'),
  new GroceryItem('Soy Milk', '$3.30'),
  new GroceryItem('Soda', '$1.99')
] let cart = new Cart(groceries) cart.prettyPrint()
(Edited: 2021-04-26)
function Cart(groceryList) { this.groceries = groceryList this.prettyPrint = function() { this.groceries.forEach(item => { console.log(@BT@${item.item} costs ${item.price}@BT@) }); } } function GroceryItem(item, price) { this.item = item this.price = price } let groceries = [ new GroceryItem('Oreos', '$3.20'), new GroceryItem('Chocolate Cake', '$5.10'), new GroceryItem('Soy Milk', '$3.30'), new GroceryItem('Soda', '$1.99') ] let cart = new Cart(groceries) cart.prettyPrint()

-- Apr 21 In-Class Exercise Thread
class Cart {
  constructor(Cart) {
    this.listItems = new Array();
    this.itemPrices = new Array();
    this.numItems = 0;
  }
  prettyPrint() {
    var i = 0;
    while (cars[i])
    {
      document.write(this.listItems[i] + ": " + this.itemPrices[i] + "
"); i++; } }
}
class Cart { constructor(Cart) { this.listItems = new Array(); this.itemPrices = new Array(); this.numItems = 0; } prettyPrint() { var i = 0; while (cars[i]) { document.write(this.listItems[i] + ": " + this.itemPrices[i] + "<br/>"); i++; } } }

-- Apr 21 In-Class Exercise Thread
function cart(groceries, prices){
        this.groceries = groceries;
        this.prices = prices;
          this.prettyPrint = function(){
              document.write("[" + this.groceries + "]" + "
"); document.write("[" + this.prices + "]" + "
"); } } food= ["chicken", "soup", "honey"]; cost= ["$2", "$1", "$5"]; aCart = new cart(food, cost); aCart.prettyPrint();
function cart(groceries, prices){ this.groceries = groceries; this.prices = prices; this.prettyPrint = function(){ document.write("[" + this.groceries + "]" + "<br />"); document.write("[" + this.prices + "]" + "<br />"); } } food= ["chicken", "soup", "honey"]; cost= ["$2", "$1", "$5"]; aCart = new cart(food, cost); aCart.prettyPrint();

-- Apr 21 In-Class Exercise Thread
<!DOCTYPE html>
<html>
    <head> 
 
    </head>
    <body>
        <script>
            var Cart = { 'tortillas' : "$3.25", 'milk': "$3.25", "eggs": "$2"}; 
 
            function prettyPrint(){
               
                document.write("Grocery List: ", "</br>");
                for (var key in Cart) {
                    document.write(key, ": ", Cart[key], "</br>");
                }
            }
            prettyPrint();
        </script> 
 
    </body>
</html>
(Edited: 2021-04-26)
<pre> <!DOCTYPE html> <html> <head> </head> <body> <script> var Cart = { 'tortillas' : "$3.25", 'milk': "$3.25", "eggs": "$2"}; function prettyPrint(){ document.write("Grocery List: ", "</br>"); for (var key in Cart) { document.write(key, ": ", Cart[key], "</br>"); } } prettyPrint(); </script> </body> </html> </pre>

-- Apr 21 In-Class Exercise Thread
function cart(groceries){ this.groceryitems = groceries[0]; this.price = groceries[1]; function prettyPrint(){
 for(let i=0;i<this.grocveryitems.length;i++){
  console.log(this.groceryitems[i] + this.price[i]);
  }
} }
function cart(groceries){ this.groceryitems = groceries[0]; this.price = groceries[1]; function prettyPrint(){ for(let i=0;i<this.grocveryitems.length;i++){ console.log(this.groceryitems[i] + this.price[i]); } } }
X