Dressed to impress

Hey gang.

I’m getting “SyntaxError: missing before statement” with the code below. I’ve looked through the other posts for this lesson, and as near as I can tell, my code should work. I’ve reloaded the browser two or three times. Any help would be appreciated. Thank you.
https://www.codecademy.com/courses/objects-ii/1/3?curriculum_id=506324b3a7dffd00020bf661#

var suitcase = {
    shirt: "Hawaiian"
};
if (suitcase.hasOwnProperty('shorts')) {
    console.log(suitcase.shorts);
}
else {
    suitcase.shorts = 'You didn't pack any shorts.';
    console.log suitcase.shorts;
};

The syntax highlighting in your post does a pretty good job of answering your question.

As a suggestion, when you can’t find errors, run it through some other interpreter with more verbose error messages. You can use your browser, nodejs, or some online one.

with respect, as new coder, that’s not terribly helpful. For instance, “hawaiian” in the first line is highlighted, but that’s the default code.

1 Like

Then you’ll want to keep looking, right. See any oddities in the coloring?
Being new doesn’t excuse you from looking!

try this one:

var suitcase = {
shirt: “Hawaiian”
};

if(suitcase.hasOwnProperty(‘shorts’))
{
console.log(suitcase.shorts);
}
else{
suitcase.shorts=“red”;
console.log(suitcase.shorts);
};

1 Like

Hey madwatch, its pretty simple. You have to put console.log(suitcase.shorts), as well as suitcase.shorts = “You didn’t pack any shorts”. The difference is there is the two quotations, ", instead of one, '. I hope this helped!

Theres an even clever way to do this, kill two birds with one stone type of way. It’s like a reverse else statement written as an if statement

https://gist.github.com/2af770e90381a57bf43c999867da99c0

thanksss, cool answer

The error is in the else statement. You opened your string with ' and closed it with ' after didn. Then t, pack, any, and shorts are undefined, and it expects a method after shorts because of the .. Then, after shorts, you open another string that contains ;, console.log suitcase.shorts;, and };. If you want to put ' inside a string as plain text, use \'. The \ will not appear. Also, you need to add () for console.log. And finally, you shouldn’t put a ; after the }. This means that in the end, your code should look like:

var suitcase = {
    shirt: "Hawaiian"
};
if (suitcase.hasOwnProperty('shorts')) {
    console.log(suitcase.shorts);
}
else {
    suitcase.shorts = 'You didn\'t pack any shorts.';
    console.log(suitcase.shorts);
}

Do not just do this, it expects a closing ' inside of ""

var suitcase = {
    shirt: "Hawaiian"
};
if (suitcase.hasOwnProperty('shorts')) {
    console.log(suitcase.shorts);
}
else {
    suitcase.shorts = "You didn't pack any shorts.";
    console.log(suitcase.shorts);
}