23/33 What in the world is a type error doing here!


#1

OK. I got a problem. It's embarrassing to say so, but I cant find my type error origins. Here is the code so you can try to find it. If you can thanks. It has me stumped hands down.

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

var sally = Person("Sally Bowles",39);
var holden = Person("Holden Caufield",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);


#3

if you run your code in another online interpeter, it will show the type error is with .species. did you define species as part of the object earlier in the code, or is this all of your code?


#4

The only thing I did to the preset code was call the Person function to the sally and holden variables, and add the .age to the sentence like the instructions said.


#6

got it. you need to add new before you define each Person. see this link for an example:


#7

Hi @designrockstar73945

You have to add new before your function to create an object :

var sally = new Person("Sally Bowles",39);
var holden = new Person("Holden Caufield",16);

Hold on :wink:


#8

I screwed up with the code above as I meant to paste this code as the one above is a attempt to solve the problem myself. I said I was confused. Here is the new code with a new problem. oh and thanks for the support, you guys probably are right with the NEW solution.

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

var sally = ("Sally Bowles",39);
var holden = ("Holden Caufield",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);


#9

Nevermind didn't work.

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 Caufield",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);


#10

@designrockstar73945 the code you just pasted above works fine... what error are you getting when you try to run it?


#11

Wait nevermind, I'll end this.post = post. I was screwing up on the writing of the name Holden Caulfield in the end when I put your suggestions to use. See what I mean?

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 Caufield",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);


#12

Look again my helpful friend