Suitcase object (Needs debug)


#1


var suitcase = {
    shirt: "Hawaiian"
};

if (suitcase.shorts === true) {
    console.log(suticase.shorts);
}else{
    suitcase.shorts = "red";
    console.log(suitcase.shorts);
}


#2

which exercise are you at? Please include the exercise url and the error message


#3

https://www.codecademy.com/en/courses/objects-ii/1/3?curriculum_id=506324b3a7dffd00020bf661#
Oops, try again. Use suitcase.hasOwnProperty("shorts") to check the property!


#4

to check if a certain property exist, you need to use hasOwnProperty which you learned in the previous exercise


#5

You need to read the instructions again because you didn't do what this exercise intended you to do.

You need to use .hasOwnProperty on suitcase.

Write an if statement that checks to see if suitcase has the shorts property.

You wrote that it's true, but is it?

var suitcase = {
    shirt: "Hawaiian"
};

I see a shirt property, but not shorts.

Also, careful with the spelling here console.log(suticase.shorts);


#6

Should I put:

if (suitcase.hasOwnProperty)

for my if statement then?


#7

hasOwnProperty() is a method to check if an object has a certain property, you need to supply the property as argument, if you don't remember, visit previous exercise


#8

var suitcase = {
shirt: "Hawaiian"
};

if (suitcase.hasOwnProperty(shorts)) {
console.log(suitcase.shorts);
}else{
suitcase.shorts = "red";
console.log(suitcase.shorts);
}
How's this?


#9

here:

if (suitcase.hasOwnProperty(shorts))

shorts should be a string, otherwise its an undefined variable


#10

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