22.Open to the Public


#1

Here is my code:

function Person(first,last,age) {
this.firstName = first;
this.lastName = last;
this.age = age;
}

var john = new Person('John','Smith',30);
var myFirst = john.firstName;
var myLast = john.lastName;

//declare variable myAge set to the age of the john object.
var myAge = new Function()
var myAge = john.Age;
john.Age = 30;

the Error is as follows: Oops, try again. Make sure myAge is equal to john's age!

but it does print out johns agem\, can someone help me please?
Thanks


#2

You should only have this

function Person(first,last,age) {
  this.firstName = first;
  this.lastName = last;
  this.age = age;
}

var john = new Person('John','Smith',30);
var myFirst = john.firstName;
var myLast = john.lastName;

//declare variable myAge set to the age of the john object.
var myAge = john.age;

And it wasn't working working because you have john.Age instead of john.age. Property Age is undefined.


#3

Thank you :grinning:


#4

You're welcome. It's a minor mistake, but try to use camelCase (start with lower case letter) for your variables and properties, that way you will eliminate a lot of these mistakes. Examples

function Person(...) {
  // only the property names are important in this example
  this.firstName = ...;
  this.lastName = ...;
  this.age = ...;
  this.country = ...;
  this.residentCity = ...;
  this.favouriteFoodOfThisPerson = ...;
  this.hasBrothers = ...;
  this.job = ...;
  // pay attention how property names start with lowercase if it is the first word
  // every other word (2nd, 3rd, ...) starts with uppercase letter
}