Dressed To Impress


#1

I completed the task but the console returned 'undefined.' I'm not entirely sure I did this correctly. Isn't it supposed to return 'shorts'?

I looked at some other threads and tried their code. I just want to understand why the console ran through even though I didn't follow the instructions properly.

var james = {
    job: "programmer",
    married: false
};

var suitcase = {
    shirt: "Hawaiian"
};

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


#2

lets break it down, the if condition evaluates to false, agree? so else run. in which you create a variable called shorts, which you give a value of suitcase.shorts, but suitcase has no shorts property, so the variable shorts gets assigned a undefined value

does this make sense?


#3

Yes, I understand. So, if I give shorts a different value instead of suitcase.shorts, say "orange" it would return that value?


#4

then shorts will be assigned a value of oranges yes, but to pass the exercise, you need a object property, so you could do for example:

var shorts = suitcase.shirt;

now shorts will hold a value of Hawaiian


#5

Would the value be 'Hawaiian' in that case?


#6

yes, it would. Sorry, my fault. I copy pasted it, but codecademy has a safegaurd, if you copy paste and then don't type anything anymore, the pasted thing won't show.


#7

Got ya. Thanks a lot!


#8