16. Arrays and Objects in JS


#1

Ok, this is driving me crazy. Obviously I am doing something not quite right. Can someone help please? Here is my code:

var myObject = {
name: 'Eduardo',
type: 'Most excellent',
interests: 'garbage sorting'
};

Comment back "Oops, try again. Did you give your interests key an array value?"
ME: Yes I did!
I know it is going to be something so simple, but whatever it i,s it is alluding me at the moment.


#2

No, you didn't. You gave it a string value, and you're supposed to give it and array value.
Examples

// array with one element
interests: [1]
    
// array with more elements
interests: [1, 2]

// array with object(s)
interests: [{}]

You see my point. Now you can add any of these arrays to your interests. Array with numbers, strings, objects...whatever you prefer.


#3

No, I'm still confused as it (to me) it looks exactly the same as codecademy ones above it (i.e. the type and the name values).
Honestly I don't mean to be a pain and I am very grateful for your help. But I really want to understand rather than copy and paste/adjust.

Thank you in advance.


#4

Got it! Thank you! Yes the instructions asked for this part to be an array - duh! Hey ho. Live and learn


#5

Did you really get it? If not, just ask and I'll try to explain more. But considering your second reply, I guess we can call it solved?


#6

oh hello , yes , velly good , thank you velly much.


#7

my code is
var myObject = {
name: 'Eduardo',
type: 'Most excellent',
// Add your code here!
interests: ["Eating potatoes,", "taking naps."].
};
and it says
Oops, try again.
There was a problem with your syntax.
Can someone help?


#8

You have dot (.) right after you close interests array. Remove it (it's one line above your last line) and you should be fine.


#9

I thought the interrupter would accept the first script below, but it did not. It did accept the second script though.


var anArray = ["Tiger", 500];

var myObject = {
name: 'Eduardo',
type: 'Most excellent',
interests: anArray[0]
};


var myObject = {
name: 'Eduardo',
type: 'Most excellent',
interests: ["Tiger"]
};


#10

you didn't give array value in interests put interests:["dhoni", "ashwin"]