var resourceRecord = function(myName, myAddress) { var resourceName = myName; var resourceAddress = myAddress; var accessRight = "HR"; return { changeName: function(updateName, privilege) { // only HR can change the name if (privilege === accessRight ) { resourceName = updateName; returntrue; } else { returnfalse; } }, changeAddress: function(newAddress) { // any associate can change the address resourceAddress = newAddress; }, showResourceDetail: function() { console.log ("Name:" + resourceName + " ; Address:" + resourceAddress); } } } // Create first record var resourceRecord1 = resourceRecord("Perry","Office"); // Create second record var resourceRecord2 = resourceRecord("Emma","Office"); // Change the address on the first record resourceRecord1.changeAddress("Home"); resourceRecord1.changeName("Perry Berry", "Associate"); // Output is false as only an HR can change the name resourceRecord2.changeName("Emma Freeman", "HR"); // Output is true as HR changes the name resourceRecord1.showResourceDetail(); // Output - Name:Perry ; Address:Home resourceRecord2.showResourceDetail(); // Output - Name:Emma Freeman ; Address:Office