Need help with the call method

I need your help. Now I am trying to complete the task. I have a function to return a line with car registration number, branch and color, but I got undefined. What is my mistake? thanks

[image]

function displayCarDetails(ownerName) {
    return `${this.ownerName} has car with number ${this.number_registration}, ${this.brand} ${this.color}`
}

const Chiron   =  { number_registration: 1915, brand: "Bugatti",    color: "Gray"};
const Corvette =  { number_registration: 2195, brand: "Chevrolet",  color: "Azure"};
const Passat   =  { number_registration: 4139, brand: "Volkswagen", color: "White"};

displayCarDetails.call(Chiron,  "Marco");
displayCarDetails.call(Corvette, "Dmytrii");
displayCarDetails.call(Passat,   "Bohdan");

console.log(displayCarDetails());

It should just be ${ownerName} and not ${this.ownerName}.

ownerName is the string argument you are passing in and not something on the this context you called the function with.

@lasjorg , i replaced to
return ${ownerName} has car with number ${this.number_registration}, ${this.brand} ${this.color}
but anyway, i get undefined

Only for the last function call you are logging. For the other three it would be the string pass to the function.

In the last function call you are not using call nor passing in any arguments.


function displayCarDetails(ownerName) {
  return `${ownerName} has car with number ${this.number_registration}, ${this.brand} ${this.color}`;
}

const Chiron = { number_registration: 1915, brand: 'Bugatti', color: 'Gray' };

const Corvette = {
  number_registration: 2195,
  brand: 'Chevrolet',
  color: 'Azure',
};

const Passat = {
  number_registration: 4139,
  brand: 'Volkswagen',
  color: 'White',
};

console.log(displayCarDetails.call(Chiron, 'Marco')); // Marco has car with number 1915, Bugatti Gray
console.log(displayCarDetails.call(Corvette, 'Dmytrii')); // Dmytrii has car with number 2195, Chevrolet Azure
console.log(displayCarDetails.call(Passat, 'Bohdan')); // Bohdan has car with number 4139, Volkswagen White

console.log(displayCarDetails()); // undefined has car with number undefined, undefined undefined