Question to 2/25


#1

How come this isn't sufficient?

    function Person(job, married, speak) {
    this.job = job;
    this.married = married;
    // add a "speak" method to Person!
    this.speak = speak;    
}

var user = new Person("Codecademy Student",false,"Hello!");
user.speak();

console.log(speak)

Why do I have to make it a function - when that isn't the case for "job" and "married"?


#2

function Person(job, married, speak) {
this.job = job;
this.married = married;
// add a "speak" method to Person!
this.speak = function() {
console.log("Hello!")
}
}

var user = new Person("Codecademy Student",false,"Hello!");
user.speak();


#3

That isn't an explanation but thanks I suppose. :smile:


#4

I have tried everything.. do not know why this code is not working.. Can somebody help me please???

var james = {
job: "programmer",
married: false
};

// set to the first property name of "james"
var aProperty = "job";
james[aProperty];

// print the value of the first property of "james"
// using the variable "aProperty"
console.log(james[aProperty]);

Error:
Oops, try again. It looks like james' job was not logged to the console.


#5

function Person(job, married) {
this.job = job;
this.married = married;
// add a "speak" method to Person!
this.speak = function() {
console.log("Hello!")
};
}

var user = new Person("Codecademy Student",false);
user.speak();