JavaScipt: Objects II, exercise 4. Can I See Your References?


#1



Oops, try again. There was a problem with your syntax.
SyntaxError: missing formal parameter


var james = {
    job: "programmer",
    married: false,
    sayJob: function(this.job) {
        // complete this method
        console.log("'Hi, I work as a " + this.job);
    }
};

// james' first job
james.sayJob(this.job);

// change james' job to "super programmer" here
james.job="super programmer";

// james' second job
james.sayJob(this.job);


#2

at your method declaration:

sayJob: function(this.job)

why do you give the method a parameter of this.job?

member variables (job and married in this case) are automatically added to this, so you can access them in methods, so no need to supply a parameter

this also means, you can you remove the argument this.job from this line:

james.sayJob(this.job);

#3

Ok, it makes sence.

So I made the changes. What is confusing that it shows I can go to "next lesson", but console is empty. (see screenshot below)


#4

that is weird, your code is fine. I think your browser might be sending cached data. Try refreshing the page, then run your code again, see if you get output


#5

It works now.

Thank you stemim94!


#6