0

This is my error, but I have some functions like that and they work. What am I doing wrong?

I try to change the prototype's name but it's the same error

function Pendejo(nickname, edad, pendejo) {
  this.nickname = nickname;
  this.edad = edad;
  this.pendejo = pendejo;
}

Pendejo.prototype.show = function() {
  return `Soy ${this.nickname} y soy ${this.pendejo}% pendejo`;
}

let ryu = new Pendejo('Ryu', 22, 100);
console.log(Pendejo.show());
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Occsy
  • 3
  • 1

2 Answers2

1

You need to invoke the function from the object ryu

function Pendejo(nickname, edad, pendejo) {
  this.nickname = nickname;
  this.edad = edad;
  this.pendejo = pendejo;
}

Pendejo.prototype.show = function() {
  return `Soy ${this.nickname} y soy ${this.pendejo}% pendejo`;
}

let ryu = new Pendejo('Ryu', 22, 100);
console.log(ryu.show());
kennarddh
  • 2,186
  • 2
  • 6
  • 21
1

You should call show() on the object, not the function:

function Pendejo(nickname, edad, pendejo) {
  this.nickname = nickname;
  this.edad = edad;
  this.pendejo = pendejo;
}

Pendejo.prototype.show = function() {
  return `Soy ${this.nickname} y soy ${this.pendejo}% pendejo`;
}

let ryu = new Pendejo('Ryu', 22, 100);
console.log(ryu.show());
chrwahl
  • 8,675
  • 2
  • 20
  • 30