Please explain why? 23.More Options


#1


Hello there! I passed the lesson but it doesn't print out the value for Sally and Holden

The OUTPUT IS:

sally's species is Homo Sapiens and she is [object Object]
holden's species is Homo Sapiens and he is [object Object]


function Person(name,age) {
  this.name = name;
  this.age = age;
  this.species = "Homo Sapiens";
}

var sally = new Person("Sally Bowles", 39);
var holden = new Person("Holden Caulfield", 16);
console.log("sally's species is " + sally.species + " and she is " + sally);
console.log("holden's species is " + holden.species + " and he is " + holden);

**Thank you so much :kiss: **


#2

Simply writing sally or holden will output [object object] because sally and holden are objects. You will have to be more specific. Objects don't output themselves, they access certain properties/variables or methods/functions and output them. The way you accessed 'species' property with sally and holden objects.

below is the code..

console.log("sally's species is " + sally.species + " and she is " + sally.age + " years old and her full name is " + sally.name );
console.log("holden's species is " + holden.species + " and he is " + holden.age + " years old and his full name is " + holden.name );

#3

Now I understand! Thank you so much @abhi.borkakoty :sparkles: :revolving_hearts:


#4

Welcome :slight_smile:


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.