Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Javascript Level 9 Lesson 9

 let player = {
name: "default_name",
weapon: "Pistol",
exp: "Pro",

// defining method
setName: function(name) {

},
getName: function() {

},
showInfo: function() {
console.log(`${this.name} uses ${this.weapon} and is ${this.exp} level player in STBattleRoyal`);
}
};

player.setName("John Wick");
player.showInfo();


Please explain me a correct code ASAP
by

1 Answer

kshitijrana14
Try this one
let player = {
name: "default_name",
weapon: "Pistol",
exp: "Pro",

// defining method
setName: function(name) {
this.name = name;

},
getName: function() {
return this.name;
},
showInfo: function() {
console.log(`${this.getName()} uses ${this.weapon} and is ${this.exp} level player in STBattleRoyal`);
}
};

player.setName("John Wick");
player.showInfo();

Login / Signup to Answer the Question.