Advertisement
Guest User

dipen Plag

a guest
Nov 12th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. /create a single variable in the global namespace
  2. //all properties are public and can be changed - can be dangerous!!
  3. var public_module_var = {
  4. price:0,
  5.  
  6.  
  7.  
  8.  
  9. showItems: function(){
  10.  
  11.  
  12. },
  13.  
  14.  
  15.  
  16.  
  17.  
  18. addPrice : function(gum_type) {
  19. var totalprice=0;
  20. if (gum_type==="extra"){
  21. document.getElementById("item_price").innerHTML=private_module_var.brands[0].price;
  22. document.getElementById("total_price").innerHTML=public_module_var.showItems();
  23. }
  24.  
  25. else if (gum_type==="doubleMint"){
  26. docment.getElementById("item_price").innerHTML=private_module_var.brands[1].price;
  27. document.getElementById("total_price").innerHTML=showItems();
  28. }
  29.  
  30. else if (gum_type==="trident"){docment.getElementById("item_price").innerHTML=private_module_var.brands[2].price;
  31. document.getElementById("total_price").innerHTML=showItems();
  32. }
  33.  
  34. else if (gum_type==="bubbleGum"){docment.getElementById("item_price").innerHTML=private_module_var.brands[3].price;
  35. document.getElementById("total_price").innerHTML=showItems();
  36. }
  37.  
  38. else{
  39. console.log("error");}
  40.  
  41. return totalprice;
  42. },
  43. clear: function(){
  44.  
  45.  
  46. },
  47.  
  48.  
  49. }
  50.  
  51.  
  52.  
  53. var private_module_var = (function() {
  54.  
  55. //private variables
  56. var brands = [{brand : "extra",
  57. price : 2},
  58. {brand : "double",
  59. price : 4},
  60. {brand:"trident",
  61. price :3},
  62. {brand:"bubble",
  63. price : 1.50}
  64. ];
  65. // var brand = new Array("extra", "double", "trident", "bubble");
  66. //var price = new Array(2, 4,3,1.50 );
  67. //var options = new Array(brand, price);
  68.  
  69. //private method
  70. var calculate_totalprice = function() {
  71. var sum=0;
  72. sum+=puutsomething ;
  73. };
  74.  
  75. return {brands:brands,
  76.  
  77. };
  78.  
  79. })();
  80.  
  81. //calling addPrice Function for Extra_gum_image
  82. document.getElementById("Extra_gum_image").addEventListener("click",function(){public_module_var.addPrice("extra")});
  83.  
  84.  
  85. //calling addPrice Function for Double_Mint_image
  86. document.getElementById("Double_Mint_image").addEventListener("click", function(){public_module_var.addPrice("doubleMint")});
  87.  
  88. //calling addPrice Function for Trident_gum_image
  89. document.getElementById("Trident_gum_image").addEventListener("click", function(){public_module_var.addPrice("trident")});
  90.  
  91. //calling addPrice Function for Bubble_Gum_image
  92. document.getElementById("Bubble_Gum_image").addEventListener("click",function(){public_module_var.addPrice("bubbleGum")});
  93. little bit improved
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement