Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
Problem with calling a method using a prototype

Hi I have this code written and I want the output to be "bill jones is a snowboarder of beginner skill on the slopes.". I am getting "function () { return this.firstName + " " + this.lastName; } is a snowboarder of beginner skill on the slopes." I think the problem is the way I am calling the fullName method but I am stuck.

https://codepen.io/stefan927/pen/yLPJdQG?editors=1111

(function() {
  const fullName = document.getElementById('fullName');
  const type = document.getElementById('type');
  const ability = document.getElementById('ability');

  function Person(firstname, lastname, type, ability) {
    this.firstName = firstname;
    this.lastName = lastname;
    this.type = type;
    this.ability = ability;
  }
  Person.prototype.fullName = function() {
    return this.firstName + " " + this.lastName;
  }

  var skier = new Person('Bill', 'Jones', 'snowboarder', 'beginner');


  fullName.textContent = skier.fullName;
  type.textContent = skier.type;
  ability.textContent = skier.ability;

}())
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Like Pointy pointed ( no pun intended ) out in his comment, you are not calling the fullName function which is invoked with a pair of (). So, in your code fullName.textContent = skier.fullName should be fullName.textContent = skier.fullName(). That should resolve your issue.

about 4 years ago · Juan Pablo Isaza Relatório

0

You have added fullName to the Persons prototype, and it's a function.
So you need to call/invoke this function.

fullName.textContent = skier.fullName(); //added () to fullName
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda