Intro to Objects II: Dressed to Impress


I'm having a bit of trouble with this code. I keep getting a "ReferenceError: shorts is not defined" message every time I try to run this code. To my understanding, the only reason I would receive this message would be if my 'if(suitcase.hasOwnProperty('shorts'))' code were running as true even though it is false, yet I'm still receiving the error. If anyone could shed a light on this for me that'd be awesome.

var suitcase = {
    shirt: "Hawaiian"

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


short is part of the suitcase object? you can use suitcase.shorts


I used 'suitcase.shorts' in the else statement to assign the value "red" to shorts. I'm still receiving the error.


can i see an updated version of your code?


There isn't an updated version, in my original code I under the else statement you can see it.


here you did it right:

suitcase.shorts = "red";

agree, but i wasn't talking about that line, i was talking about this line:


shorts is a property of suitcase object, so you need objectName.propertyName


Ah I see now, that fixed it. Thank you!

suitcase.shorts = "red";