23. More Options


#1

My message did pass but instead of printing their ages it prints "undefined". How do i define/fix it to say their ages?


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 " + this.age);
console.log("holden's species is " + holden.species + " and he is " + this.age);


#2

Or am i supposed to manually add their ages; i.e. 39, 16?


#3

You have to manuelly add the numbers in like this below. Now their might be another way to do it but this is how I just assumed it was to work

console.log("sally's species is " + sally.species + " and she is " + 39);
console.log("holden's species is " + holden.species + " and he is " + 16);

#4

Hi

Or am i supposed to manually add their ages; i.e. 39, 16?

No, you should do it like you did for the species.


#5

nick, keep in mind that you have to print the ages of sally and holden. The age of sally is found in sally.age, while the age of holden is found in sally.holden.

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


#6

I have also got a problem with this task, it always sais "SyntaxError: Unexpected token )". Here is my code. The backslashs are to continue the line, without them it just sais "SyntaxError: Invalid or unexpected token".

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.age + " years\
old".);
console.log("holden's species is " + holden.species + " and he is " + holden.age+ " years\
old.");


#7

console.log("sally's species is " + sally.species + " and she is " + sally.age + " years\
old".);

. should be inside " "

years\old".)


#8

Having a problem with this one as well.

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.age );
console.log("holden's species is " + holden.species + " and he is " + holden.age);

Your code threw the following error when sally's name was checked: TypeError: Cannot read property 'name' of undefined


#9

Maybe try capitalizing Person in:

var sally = new person("Sally Bowles", 39);
var holden = new person("Holden Caulfield", 16);


#10

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