8/30 Question


#1

I can't seem to figure out what I've got going wrong here. The error popping up is "shorts is undefined", but isn't that what the if statement is for?

var suitcase = {
shirt: "Hawaiian"
};

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


#2

Because in objects those values are only in the object, you need to call it like
suitcase.shorts instead of just shorts, because shorts is not made, but shorts inside of suitcase is.


#3

AH. Thank you. That makes total sense!


#4

var suitcase = {
shirt: "Hawaiian"

};

if(suitcase.hasOwnProperty("shorts")) {
console.log("red");
}
else {
suitcase.shorts = "red";
console.log(shorts);
};
I see the above issue and have attempted to call it to no avail, any suggestions would be greatly appreciated.


#5

never mind, this is solved, realized my suitcase.shorts issue in the console.log.