8. Dressed to Impress - *need code check*


#1

I'm getting the message "ReferenceError: shorts is not defined." What's not quite right here? Thanks.

var suitcase = {
shirt: "Hawaiian"
};

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

console.log(suitcase.shorts);


#2

on this line

it should rather be

if (suitcase.hasOwnProperty('shorts') === true) {

but since suitcase.hasOwnProperty('shorts') will return a boolean value you can just write

if (suitcase.hasOwnProperty('shorts')) {

#3

First of all you didnt understand how to check if an object has a property. This is not how you check if an object has a property:

I am not going to give you exact anwser but an example so you can implement it to your code

if(something.hasOwnProperty("someproperty")){

Hope this helped!


#4

@amanuel2 thank you! and happy birthday


#5

@rydan thanks! totally forgot about the quotes


#6

Thankyou so much!!!!