Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(){
- class Product {
- var productType;
- var name;
- var price;
- constructor(productType, name, price){
- this.productType = productType;
- this.name = name;
- this.price = price;
- }
- get name(){
- return this.name;
- }
- get productType(){
- return this.productType;
- }
- get price(){
- return this.price;
- }
- set name(){
- return this.name;
- }
- set productType(productType){
- if(typeof productType == "string"){
- this.productType = productType;
- }else this.productType = '';
- }
- set price(price){
- if(isNAN(price)== true){
- if(price>=0){
- this.price = price;
- }else this.price = 0;
- }
- }
- /* .... */
- }
- class ShoppingCart {
- var products = [];
- constructor(){
- };
- function add(product){
- this.products.push(product);
- }
- function remove(product){
- for ( var i = 0; i<this.products.length ;i++) {
- if(this.products.name==product.name){
- if(this.products.productType==product.productType){
- this.products.price==product.price{
- this.product.splice(i,1);
- break;
- }
- }
- }
- }
- }
- /* .... */
- }
- return {
- Product, ShoppingCart
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement