0

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

}
3
  • 1
    console.log(printBio()) Commented Aug 6, 2022 at 20:28
  • seems you placed the call to printBio(); inside the function after the return, which wont work Commented Aug 6, 2022 at 20:28
  • The code editor button is your friend [<>] it opens up to a world of possibilities like legible code. Commented Aug 6, 2022 at 20:29

2 Answers 2

2

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);
};
Sign up to request clarification or add additional context in comments.

Comments

0
function printBio(user) {
  return `This is ${user.name} ${user.surname} from ${user.address.country}.`
}

This is the solution that was given by the platform

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.