4. [job] is not defined error


#1


The console throws job is not defined error while the exercise is counted as PASS. Apparently [job] notation I used to refer to the property inside of the method is not recognized. I just want to make sure that the error is a glitch of the sandbox rather than a malnotation example.

https://www.codecademy.com/courses/objects-ii/0/4?curriculum_id=506324b3a7dffd00020bf661

I shouldn't receive the error


var james = {
    job: "programmer",
    married: false,
    sayJob: function() {
        console.log("Hi, I work as a " + [job]);
    }
};

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

// change james' job to "super programmer" here
james.job("superprogrammer");

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


#2

Don't put job in brackets, just type it in as it is,


#3

I tried removing the square brackets, but it didn't help. I still keep getting the error.


#4

to call it globally you have to include this. before job so it should look like for example

("Hi I work as " + this.job + ".")


#5

Refreshing my browser AND removing the square brackets helped


#6

console.log("Hi, I work as a " + this.job); That worked for me.


#7

First, console.log("Hi, I work as a " + this.job); and It worked!
Otherwise, instead of james.job("superprogrammer"); It should be james.job = "super programmer" ;


#8

This is the full answer:

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

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

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

// james' second job
james.sayJob("really super programmer");

I noticed that whoever made these new lessons for codecademy in javascript has a lot of holes in his/her code. Whoever made this I feel does a terrible job teaching how to code.


#9

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