Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. function solve(){
  2. class Product {
  3. var productType;
  4. var name;
  5. var price;
  6. constructor(productType, name, price){
  7. this.productType = productType;
  8. this.name = name;
  9. this.price = price;
  10. }
  11.  
  12. get name(){
  13. return this.name;
  14. }
  15. get productType(){
  16. return this.productType;
  17. }
  18.  
  19. get price(){
  20. return this.price;
  21. }
  22.  
  23. set name(){
  24. return this.name;
  25. }
  26. set productType(productType){
  27. if(typeof productType == "string"){
  28. this.productType = productType;
  29. }else this.productType = '';
  30. }
  31.  
  32. set price(price){
  33. if(isNAN(price)== true){
  34. if(price>=0){
  35. this.price = price;
  36. }else this.price = 0;
  37.  
  38. }
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. /* .... */
  46. }
  47.  
  48.  
  49.  
  50. class ShoppingCart {
  51. var products = [];
  52. constructor(){
  53.  
  54. };
  55. function add(product){
  56. this.products.push(product);
  57. }
  58. function remove(product){
  59. for ( var i = 0; i<this.products.length ;i++) {
  60. if(this.products.name==product.name){
  61. if(this.products.productType==product.productType){
  62. this.products.price==product.price{
  63. this.product.splice(i,1);
  64. break;
  65. }
  66. }
  67. }
  68. }
  69.  
  70. }
  71. /* .... */
  72. }
  73. return {
  74. Product, ShoppingCart
  75. };
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement