Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /create a single variable in the global namespace
- //all properties are public and can be changed - can be dangerous!!
- var public_module_var = {
- price:0,
- showItems: function(){
- },
- addPrice : function(gum_type) {
- var totalprice=0;
- if (gum_type==="extra"){
- document.getElementById("item_price").innerHTML=private_module_var.brands[0].price;
- document.getElementById("total_price").innerHTML=public_module_var.showItems();
- }
- else if (gum_type==="doubleMint"){
- docment.getElementById("item_price").innerHTML=private_module_var.brands[1].price;
- document.getElementById("total_price").innerHTML=showItems();
- }
- else if (gum_type==="trident"){docment.getElementById("item_price").innerHTML=private_module_var.brands[2].price;
- document.getElementById("total_price").innerHTML=showItems();
- }
- else if (gum_type==="bubbleGum"){docment.getElementById("item_price").innerHTML=private_module_var.brands[3].price;
- document.getElementById("total_price").innerHTML=showItems();
- }
- else{
- console.log("error");}
- return totalprice;
- },
- clear: function(){
- },
- }
- var private_module_var = (function() {
- //private variables
- var brands = [{brand : "extra",
- price : 2},
- {brand : "double",
- price : 4},
- {brand:"trident",
- price :3},
- {brand:"bubble",
- price : 1.50}
- ];
- // var brand = new Array("extra", "double", "trident", "bubble");
- //var price = new Array(2, 4,3,1.50 );
- //var options = new Array(brand, price);
- //private method
- var calculate_totalprice = function() {
- var sum=0;
- sum+=puutsomething ;
- };
- return {brands:brands,
- };
- })();
- //calling addPrice Function for Extra_gum_image
- document.getElementById("Extra_gum_image").addEventListener("click",function(){public_module_var.addPrice("extra")});
- //calling addPrice Function for Double_Mint_image
- document.getElementById("Double_Mint_image").addEventListener("click", function(){public_module_var.addPrice("doubleMint")});
- //calling addPrice Function for Trident_gum_image
- document.getElementById("Trident_gum_image").addEventListener("click", function(){public_module_var.addPrice("trident")});
- //calling addPrice Function for Bubble_Gum_image
- document.getElementById("Bubble_Gum_image").addEventListener("click",function(){public_module_var.addPrice("bubbleGum")});
- little bit improved
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement