Dressed to impress lesson. feels like error should of popped up


#1


var suitcase = {
    shirt: "Hawaiian"
};
if(suitcase.hasOwnProperty("Shorts")){
    console.log("suitcase present");
}
else if(suitcase.Shorts){
    console.log("shorts present");
}
else{
    console.log("No options");
};

this code worked for the lesson but i feel like it should not have... anyone know if this is 100% correct?


#2

why shouldn't it work?


#3

100% correct:

var suitcase = {
    shirt: "Hawaiian"
};
// so suitcase has one property named shirt

if(suitcase.hasOwnProperty("Shorts")){ // returns false
    console.log("suitcase present");
}
else if(suitcase.Shorts){ // returns false
    console.log("shorts present");
}
else{
    console.log("No options");
};

// result
"No options"

If you need to print some option, do changes:

suitcase.hasOwnProperty("Shorts") -> suitcase.hasOwnProperty("shirt")
OR
suitcase.Shorts -> suitcase.shirt

#4

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