8. Dress To Impress


#1

https://www.codecademy.com/courses/objects-ii/1/3?curriculum_id=506324b3a7dffd00020bf661#

Hello,
I keep getting this error message
SyntaxError: Unexpected identifier

Here is my code:

I tried answers from other posts but didn't work. Also I refreshed page just in case but still getting the same error

var suitcase = {
    shirt: "Hawaiian"
    shorts
};

if (suitcase.hasOwnProperty ("shorts") ) {
console.log(shorts);
} else {
suitcase.shorts = "red";
console.log(shorts);
};


#2

you need to identify "shorts"

for example shorts: "whatever"

also, place a comma ( , ) after declaring the shirt


#3

Typed shorts: "sh", placed comma but I'm getting this error now:
ReferenceError: shorts is not defined

The code looks like that now:

var suitcase = {
shirt: "Hawaiian",
shorts: "sh"
};

if (suitcase.hasOwnProperty ("shorts")) {
console.log(shorts);
}
else {
suitcase.shorts = "red";
console.log(shorts);
};


#4

sorry, my bad, remove completely " shorts : "sh" " and delete comma

you do not need either of those 2

after if add "suitcase.shorts = "sh" "J

Just like this

var suitcase = {
shirt: "Hawaiian"
};

if(!suitcase.hasOwnProperty("shorts"))
{
suitcase.shorts = "Greek";
console.log(suitcase.shorts);
}
else{
console.log(suitcase.shorts);
}


#5

Ty this works :slight_smile:


#6

A faster solution for you, if you wish to look at!

var suitcase = {
shirt: "Hawaiian"
};

if(!suitcase.hasOwnProperty('shorts'))
{
suitcase.shorts = "jeans";
}
console.log(suitcase.shorts);


#7

I will check this also.
Thanks for your response :slight_smile:


#8

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