8/30 Dressed to Impress

Hello,

i am a little confused at the moment because of my syntax.

First it looked like this:

var suitcase = {
shirt: “Hawaiian”,
};

if(suitcase.hasOwnProperty(“shorts”)){
console.log(suitcase[shorts]);
}
else{
suitcase.shorts = “Badehose”;
console.log(suitcase[shorts]);
}

It always replied with an error.

Then i changed it to:

var suitcase = {
shirt: “Hawaiian”,
};

if(suitcase.hasOwnProperty(“shorts”)){
console.log(suitcase[shorts]);
}
else{
suitcase.shorts = “Badehose”;
** console.log(suitcase.shorts);**
}

and it works.

What’s the difference between the notation console.log(suitcase[shorts]); and console.log(suitcase.shorts);?

I thought it would be the same?

Thank you in advance.

In bracket notation, you should have quotes. Example:

var hash = {
    name: "Cade"
}
console.log(hash["name"])

Thanks, that was the mistake i didn’t notice.

also in the second run of your code, i removed the *'s in it and the code passed. just fyi