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

244
Visualizações
How to print a return statement from an Object in JavaScript?

so Im trying to get my code to print out a message that returns 'This is Bob Martin from USA'.

This is what I did so far. I've been trying to figure out what went wrong but can't seem to get this to work. I provided comments to guide my thought processes


function printBio(user) {

  // function to print message, user is the object and parameter for my function 

  // User object that possesses properties as displayed

  let user = {
    name: 'Bob',
    surname: 'Martin',
    age: 25,
    address: '',
    country: "USA"
  }
}

    return 'This is ' + user.name + ' ' + user.surname + ' from ' + user.country + '.';

    // My attempt for a return statement to print my desired message   

    printBio();

    // The last step, which is to simply have the function do its job and print the message according to the return statement

}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you are trying to get a built in method to tag onto your user object:

class User {
    constructor(name, surname, age, address, country) {
    this.name = name;
        this.surname = surname, 
        this.age = age;
        this.address = address;
        this.country = country;
    }

    printBioMethod() {
        const bio = `This is ${this.name} ${this.surname} from ${this.country}.`;
        console.log(bio);
    }
}

Or If you prefer an external function to pull out the objects variables

const printBioFunction = obj => {
    const { name, surname, country } = obj;
    const bio = `This is ${name} ${surname} from ${country}.`;

    console.log(bio);
};
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