function creatUser(name, score = 0) {
let user = {};
user.name = `Amir`;
user.score = 0;
user.increaseScore = function (value = 1) {
user.score = user.score + value;
return user.score;
};
user.decreaseScore = function (value = 1) {
user.score = user.score - value;
return user.score;
};
user.changeName = function (name) {
user.name = name;
return user.name;
};
return user;
}
let user1 = creatUser(`Sameer`, 20);
let user2 = creatUser(`Zoya`);
Blockquote when I access user1 it will go through an error
user1 alreay definedand when I access user2 then it will not retrun updated values.
First of all , the code is working well and secondly you should use class for doing this !