8. Dressed to Impress


#1


Hi, I have a problem with this exercise... may somebody help me?
this is the question:
Write an if statement that checks to see if suitcase has the shorts property.

If your if statement evaluates to true, print the value of the shorts property.

If your if statement evaluates to false, set the shorts property to any value you wish using dot notation. Then print the value of the shorts property.

Could you show me how can I do it?
thank you


var suitcase = {
    shirt: "Hawaiian"
};
if (){

}
else{
    
}


#2

The code below works, a hope that was the point.

var suitcase = {

shirt: "Hawaiian"

};
if (suitcase.hasOwnProperty("shorts")){
suitcase.shorts="nic";
}
else{
suitcase.shorts="cos";

}

console.log(suitcase.shorts);


#3

var suitcase = {
shirt: "Hawaiian",

};

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


#4

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