scripts/todo.js
// when user add an item to the cart
when user add an item to the cart
when user add an item to the cart
function addToCart(button_id) {
    var new_product;
    if (button_id == "couch_add") {
        var quantity = parseInt(document.getElementById("couch_quantity").value);
        new_product = new Product("couch", 25, "square", quantity);
    }
    else if (button_id == "bed_add") {
        var quantity = parseInt(document.getElementById("bed_quantity").value);
        new_product = new Product("bed", 18, "square", quantity);
    }
    else if (button_id == "round_add") {
        var quantity = parseInt(document.getElementById("round_quantity").value);
        new_product = new Product("round", 15, "square", quantity);
    }
    else if (button_id == "floor_add") {
        var quantity = parseInt(document.getElementById("floor_quantity").value);
        new_product = new Product("floor", 25, "square", quantity);
    }
    var inCart = false;
    if (cartList[0] >= 1){
        for (i = 1; i < cartList.length; i++){
            var name = cartList[i].product_name;
            if (new_product.product_name == name ){
                cartList[i].quantity += 1;
                inCart = true;
            }
        }
    }
    if (inCart == false) {
        cartList.push(new_product);
    }
    cartList[0] += 1;
    var customer_cart = document.getElementById("cart");
    customer_cart.innerHTML = "Cart (" + cartList[0] + ")";
    console.log(cartList.length);
    for (i = 1; i < cartList.length; i++){
        console.log(cartList[i].product_name + cartList[i].quantity);
    }
}
function addToCart ( button_id ) { var new_product ; if ( button_id == "couch_add" ) { var quantity = parseInt ( document . getElementById ( "couch_quantity" ) . value ) ; new_product = new Product ( "couch" , 25 , "square" , quantity ) ; } else if ( button_id == "bed_add" ) { var quantity = parseInt ( document . getElementById ( "bed_quantity" ) . value ) ; new_product = new Product ( "bed" , 18 , "square" , quantity ) ; } else if ( button_id == "round_add" ) { var quantity = parseInt ( document . getElementById ( "round_quantity" ) . value ) ; new_product = new Product ( "round" , 15 , "square" , quantity ) ; } else if ( button_id == "floor_add" ) { var quantity = parseInt ( document . getElementById ( "floor_quantity" ) . value ) ; new_product = new Product ( "floor" , 25 , "square" , quantity ) ; } var inCart = false ; if ( cartList [ 0 ] >= 1 ) { for ( i = 1 ; i < cartList . length ; i ++ ) { var name = cartList [ i ] . product_name ; if ( new_product . product_name == name ) { cartList [ i ] . quantity += 1 ; inCart = true ; } } } if ( inCart == false ) { cartList . push ( new_product ) ; } cartList [ 0 ] += 1 ; var customer_cart = document . getElementById ( "cart" ) ; customer_cart . innerHTML = "Cart (" + cartList [ 0 ] + ")" ; console . log ( cartList . length ) ; for ( i = 1 ; i < cartList . length ; i ++ ) { console . log ( cartList [ i ] . product_name + cartList [ i ] . quantity ) ; } }
when user add an item to the cart
when user add an item to the cart
// add product into cart //change the cart number // print in console for debugging