4_ Can I see your references JS Object ll


#1

I m told my answer is wrong YET , it prints the good 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();

Console :
Hi, I work as a programmer
Hi, I work as a super programmer

"It looks like your sayJob() method does not properly log ‘Hi, I work as a [job]’ to the console "

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


#2

Hi @slibre2,

Why do you have extra quotation marks there?

Your console should print exactly:

‘Hi, I work as a [job]’

with no extra spaces, delete the extra ones, then your code will work.


Note: In order for people to help you better next time, it is timely and good practice to post your code according to the following format. Hope you have a look on that.

Cheers :slight_smile:


#3

Thanks for your help but …
…I m sorry but it still doesn’t work !
I thought we have to replace the word job between curly brackets and not put itin the code , haven’t we ?
here is the link :

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


#4

Hi @slibre2,

I think you have misunderstood what I was saying.

I quoted ‘Hi, I work as a [job]’ from the error that you had, from what you posted here:

You took my words too literally and try to understand this part of my question:

Currently your code does not print the correct sentences:

You said it printed:

Hi, I work as a programmer
Hi, I work as a super programmer

But in actual fact, it printed with double spaces:

Hi, I work as a  programmer
Hi, I work as a  super programmer

You can see it in your code, the problem lies in here:

console.log("Hi, I work as a "+" "+ this.job)

You have a double spaces, thus, I was asking why do you need/have extra quotation marks.

Change the console.log, delete the extra spaces and quotation marks so your console would print the following format of:

‘Hi, I work as a [job]’

Which are:

Hi, I work as a programmer
Hi, I work as a super programmer

with no extra spaces.


Does that make sense? Just give it one more go. Thank you.


#5

Oh yes ! It works but it was just a question of quotes and double quotes ??? I m surprised . I thought there were equivalent . " " = ’ ’ ?
Thanks very much for your help Codexthon !


#6

Glad it works. Could you post your code here again? I don’t quite understand your question.

The point is not about the quotation marks, it’s more about the one extra space inside the quotation marks. I can elaborate more if I could see your code.


#7

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();

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

I msuprised because at the beginning I wrote it like this ???


#8

No @slibre2,

Writing this:

console.log("Hi, I work as a "+ " " + this.job)

is totally different versus:

console.log('Hi, I work as a '+ this.job)

The first one add one extra " " space in between the sentence.


For your information, you can write either: (with double quotes " ")

console.log("Hi, I work as a " + this.job)

or (with single quote ’ ')

console.log('Hi, I work as a ' + this.job)

Both are correct.


:slight_smile:


#9

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